package com.lvjunxiong.serviceinterface;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.lvjunxiong.serviceinterface.bi.BIModel;
import com.lvjunxiong.serviceinterface.salary.S_Model;
import com.lvjunxiong.serviceinterface.salary.SalaryModel;
import com.lvjunxiong.serviceinterface.sms.SMSLogin;
import com.lvjunxiong.serviceinterface.sms.SMSModel;
import com.lvjunxiong.serviceinterface.tongxun.*;
import com.opensymphony.xwork2.ActionSupport;
import common.ApproveModel;
import common.CommModel;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpStatus;
import org.apache.http.StatusLine;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.codehaus.jackson.map.ObjectMapper;

import org.dom4j.*;
import utils.JsonUtils;
import utils.MD5Utils;
import utils.PageModel;
import utils.WeiXinKey;
import javax.servlet.http.HttpServletResponse;
import javax.xml.soap.*;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.*;
import static com.lvjunxiong.serviceinterface.Serviceutil.doPost;
/**
 * Created by lvjunxiong on 2019/2/11.
 */
public class ServiceAction extends ActionSupport {
    private static final long serialVersionUID = 1L;
    private static Logger logger = Logger.getLogger(ServiceAction.class);
    private HttpServletResponse response;
    private String code;
    private String access_token;
    private String id;
    private String title;
    private ServiceDao dao = new ServiceDao();
    private String openid;
    private String username;
    private String userpass;
    private String parayId;
    private String months;
    private String c_time;
    private String party_id;
    private String phone;
    private String yzm;
    private String bmid;
    private String userid;
    private String jtid;
    private String xh;
    private String corpname;
    private String phonejson;
    private String jtids;
    private String useways;
    
    private String useway;
    
    
    public String getUseway() {
		return useway;
	}

	public void setUseway(String useway) {
		this.useway = useway;
	}

	public String getJtids() {
		return jtids;
	}

	public void setJtids(String jtids) {
		this.jtids = jtids;
	}
    public String getUseways() {
		return useways;
	}

	public void setUseways(String useways) {
		this.useways = useways;
	}

	public String getYanzhenma() {
		return yanzhenma;
	}

	public void setYanzhenma(String yanzhenma) {
		this.yanzhenma = yanzhenma;
	}

	private String yanzhenma;
    

    //分页开始
    private Integer page; //当前页码
    private Integer total;//总条数
    private Integer pagesize;//当前页显示的数据行数
    private Integer record;//当前数据条数
    List<FawenModel> list = new ArrayList<FawenModel>();
    //分页结束

    List<NewmessageModel> newmessagelist = new ArrayList<NewmessageModel>();

    public String getPhonejson() {
        return phonejson;
    }

    public void setPhonejson(String phonejson) {
        this.phonejson = phonejson;
    }

    public String getYzm() {
        return yzm;
    }

    public void setYzm(String yzm) {
        this.yzm = yzm;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getAccess_token() {
        return access_token;
    }

    public void setAccess_token(String access_token) {
        this.access_token = access_token;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getOpenid() {
        return openid;
    }

    public void setOpenid(String openid) {
        this.openid = openid;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getUserpass() {
        return userpass;
    }

    public void setUserpass(String userpass) {
        this.userpass = userpass;
    }

    public String getParayId() {
        return parayId;
    }

    public void setParayId(String parayId) {
        this.parayId = parayId;
    }

    public String getMonths() {
        return months;
    }

    public void setMonths(String months) {
        this.months = months;
    }

    public String getC_time() {
        return c_time;
    }

    public void setC_time(String c_time) {
        this.c_time = c_time;
    }

    public List<FawenModel> getList() {
        return list;
    }

    public void setList(List<FawenModel> list) {
        this.list = list;
    }

    public Integer getPage() {
        return page;
    }

    public void setPage(Integer page) {
        this.page = page;
    }

    public List<NewmessageModel> getNewmessagelist() {
        return newmessagelist;
    }

    public void setNewmessagelist(List<NewmessageModel> newmessagelist) {
        this.newmessagelist = newmessagelist;
    }

    public Integer getTotal() {
        return total;
    }

    public void setTotal(Integer total) {
        this.total = total;
    }

    public Integer getPagesize() {
        return pagesize;
    }

    public void setPagesize(Integer pagesize) {
        this.pagesize = pagesize;
    }

    public Integer getRecord() {
        return record;
    }

    public void setRecord(Integer record) {
        this.record = record;
    }

    public String getParty_id() {
        return party_id;
    }

    public void setParty_id(String party_id) {
        this.party_id = party_id;
    }

    public String getBmid() {
        return bmid;
    }

    public void setBmid(String bmid) {
        this.bmid = bmid;
    }

    public String getUserid() {
        return userid;
    }

    public void setUserid(String userid) {
        this.userid = userid;
    }

    public String getJtid() {
        return jtid;
    }

    public void setJtid(String jtid) {
        this.jtid = jtid;
    }

    public String getXh() {
        return xh;
    }

    public void setXh(String xh) {
        this.xh = xh;
    }

    public String getCorpname() {
        return corpname;
    }

    public void setCorpname(String corpname) {
        this.corpname = corpname;
    }

    //登录接口
    public void findCode() throws Exception {
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        String client_id = WeiXinKey.getKey("client_id").trim();
        String response_type = WeiXinKey.getKey("response_type").trim();
        String redirect_uri = WeiXinKey.getKey("redirect_uri").trim();
        String gain_code = Serviceutil.getCode(client_id, response_type, redirect_uri,username,userpass);
        if (gain_code != "error") {
            CommModel model = new CommModel();
            model.setResult(gain_code);
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(model, "success", "获取code成功！"));
        } else {
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "fail", "获取code失败！"));
        }
    }

    //根据code获取accesstoken接口
    /**
     * http://localhost:8080/hh/gain_Accesstoken.action?code=76610c48f23146c6e8dc7fb37f145b75
     * http://localhost:8080/hh/gain_Accesstoken.action?code=3f3f18f1ff8d949af095f2f68062e49d
     *
     * ddf52267d5707fbaaa68e30e89d06cee
     *
     * @throws Exception
     */
    public void gain_Accesstoken() throws Exception {
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        String client_id = WeiXinKey.getKey("client_id").trim();
        String redirect_uri = WeiXinKey.getKey("redirect_uri").trim();
        String grant_type = WeiXinKey.getKey("grant_type").trim();
        String client_secret = WeiXinKey.getKey("client_secret").trim();
        if (code.equals("")) {
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "fail", "code不能为空！"));
        } else {
            Map<String, Object> paramMap = new HashMap<String, Object>();
            paramMap.put("client_id", client_id);
            paramMap.put("grant_type", grant_type);
            paramMap.put("code", code);
            paramMap.put("redirect_uri", redirect_uri);
            paramMap.put("client_secret", client_secret);
            String gain_a_token = doPost("http://app.shuhai.cc/isms/oauth/accessToken", paramMap);
            logger.info(gain_a_token + "打印出来的串：" + gain_a_token);
            JSONObject jsonObject = JSONObject.fromObject(gain_a_token);
            String res = "";
            if (jsonObject.has("error")) {
                objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "fail", "获取授权码错误！"));
            } else {
                String access_token = jsonObject.get("access_token").toString();
                logger.info("从json串里获取的accesstoken:" + access_token);
                CommModel model = new CommModel();
                model.setResult(access_token);
                objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(model, "success", "获取accesstoken成功！"));
            }
        }
    }

    //获取团体id接口
    /**
     * http://localhost:8080/hh/gain_TuantiId.action?access_token=96990a9d2d355a6b673f83c6ef77a6d6
     *http://localhost:8080/hh/gain_TuantiId.action?access_token=57e8b1dd803a7b7e64a4d9856ad6fa1e
     * result：
     *{"data":{"result":"40280a81681e33ce01681e33f5240000"},"status":"success","desc":"获取团体id成功！"}
     * @throws Exception
     */
    public void gain_TuantiId() throws Exception {
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        String result = doPost("http://app.shuhai.cc/isms/oauth/userinfo", access_token);
        JSONObject jsonObject = JSONObject.fromObject(result);
        String resultStr = jsonObject.toString();
        JsonParser jp = new JsonParser();
        //将json字符串转化成json对象
        JsonObject jo = jp.parse(resultStr).getAsJsonObject();
        String partyId = jo.get("object").getAsJsonObject().get("partyId").getAsString();
        CommModel model = new CommModel();
        model.setResult(partyId);
        objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(model, "success", "获取团体id成功！"));
    }

    //轮播图接口
    public void gainLunbotuList() throws Exception {
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        List<LunbotuModel> list = dao.gainLunbotuList();
        if(list.size() >0){
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(list, "success", "获取轮播图列表成功！"));
        }else{
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "fail", "获取轮播图列表失败！"));
        }
    }

    //轮播图详情接口
    public void gainLunbotuListId() throws Exception {
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        LunbotuIdModel model = dao.gainLunbotuListId(id);
        if (model != null) {
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(model, "success", "获取轮播图详情接口成功！"));
        } else {
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "fail", "获取轮播图详情接口失败！"));
        }
    }

    //月报工资
    public void new_messageListyuepao() throws Exception {
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        List<NewmessageModel> list = dao.new_messageListgong();
        if(list.size() >0){
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(list, "success", "获取月报工资表成功！"));
        }else{
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "fail", "获取月报工资表失败！"));
        }
    }

    //最新资讯初始化列表
    public void new_messageList() throws Exception {
    	System.out.println("进去最新资讯初始化列表+++++++++++++++++++++++++");
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        List<NewmessageModel> list = dao.new_messageList();
        if (list.size() > 0) {
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(list, "success", "最新资讯初始化列表成功！"));
        } else {
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "fail", "最新资讯初始化列表失败！"));
        }
    }

    //最新资讯更多初始化列表
    public void new_messageList_less() throws Exception {
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        PageModel pmm = new PageModel();
        pmm.setCurrentPage(page);
        pmm = dao.new_messageList_less(pmm);
        //总的记录数
        record = pmm.getTotalRecord();
        //总页数
        total = pmm.getTotalPage();//total:总页数
        newmessagelist = pmm.getList();
        if (newmessagelist.size() > 0) {
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSONPage(newmessagelist, total, page, "success", "最新资讯更多初始化列表成功！"));
        } else {
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "fail", "无数据"));
        }
    }

    //最新资讯更多搜索标题接口
    public void new_messageList_less_title() throws Exception {
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        List<NewmessageModel> list = dao.new_messageList_less_title(title);
        if (list.size() > 0) {
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(list, "success", "最新资讯更多搜索标题列表成功！"));
        } else {
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "fail", "最新资讯更多搜索标题列表失败！"));
        }
    }

    //最新资讯初始化详情列表
    public void new_messageListId() throws Exception {
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        ServletActionContext.getResponse().setHeader("Access-Control-Allow-Origin", "*");//跨域问题解决
        NewmessageIdModel model = dao.new_messageListId(id);
        if (model != null) {
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(model, "success", "最新资讯初始化详情成功！"));
        } else {
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "fail", "最新资讯初始化详情失败！"));
        }
    }

    //获取openid接口
    public void gainOpenId() throws Exception {
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        HttpURLConnection conn = null;
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        SousouModel model = new SousouModel();
        String openid = "";
        String appid = "wx2942b4cfbb2b818d";
        String secret = "cdcc003ea69ee17fc20e9dffc7e1d823";
        String grant_type = "authorization_code";
        String url = "https://api.weixin.qq.com/sns/jscode2session";
        System.out.println("進入+++++++++++userOpenid"+code);
        String str = "appid=" + appid + "&secret=" + secret + "&js_code=" + code + "&grant_type=" + grant_type;
        logger.info("打印的串====" + url + "?" + str);
        try {
            URL net = new URL(url);
            conn = (HttpURLConnection) net.openConnection();
            conn.setConnectTimeout(30000); // 设置连接主机超时（单位：毫秒)
            conn.setReadTimeout(30000); // 设置从主机读取数据超时（单位：毫秒)
            conn.setDoOutput(true); // post请求参数要放在http正文内，顾设置成true，默认是false
            conn.setDoInput(true); // 设置是否从httpUrlConnection读入，默认情况下是true
            conn.setUseCaches(false); // Post 请求不能使用缓存
            conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            conn.setRequestMethod("POST");// 设定请求的方法为"POST"，默认是GET
            conn.setRequestProperty("Charset", "UTF-8");
            OutputStream out = conn.getOutputStream();
            out.write(str.getBytes());
            out.flush();
            out.close();
            String respStr = "";
            respStr = PayCommonUtil.getOut(conn);
            @SuppressWarnings("rawtypes")
            Map mapResult = objectMapper.readValue(respStr, Map.class);
            logger.info("mapResult:" + mapResult.toString());
            if (mapResult.get("errcode") != null) {
                logger.info("----------获取用户微信id失败--------" + mapResult.get("errcode"));
            } else {
                logger.info("----------获取用户微信id成功--------" + mapResult.get("openid"));
                openid = (String) mapResult.get("openid");
                model.setResult(openid);
            }
        } catch (Exception e) {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            e.printStackTrace(pw);
            logger.info("----------------------------获取用户微信id异常---------------------------" + sw.toString());
        } finally {
            if (conn != null) {
                conn.disconnect();//断开连接
            }
        }
        objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(model, "success", "获取到的code！"));
    }

    //查询用户是否授权接口
    public void queryUser_openid() throws Exception {
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        HttpURLConnection conn = null;
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        SousouModel model = dao.queryUser_openid(openid);
        if(model != null){
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "success", "用户已授权"));
        }else{
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "fail", "用户未授权"));
        }
    }

    //用户确认微信授权登录接口
//    public void insertUser_openid() throws Exception {
//        response = ServletActionContext.getResponse();
//        ObjectMapper objectMapper = new ObjectMapper();
//        HttpURLConnection conn = null;
//        response.setHeader("Content-Type", "application/json;charset=UTF-8");
//        SousouModel model = dao.queryUser_openid(openid);
//        if(model != null){
//            int j = dao.updateUser_openid(openid,model.getId());
//            if(j>0){
//                objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "success", "用户确认授权登录成功"));
//            } else {
//                objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "fail", "用户确认授权登录失败"));
//            }
//        }else{
//            int i = dao.insertUser_openid(openid);
//            if (i>0) {
//                objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "success", "用户确认授权登录成功"));
//            } else {
//                objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "fail", "用户确认授权登录失败"));
//            }
//        }
//    }

    //发文精粹列表接口
    public void queryFawen() throws Exception {
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        HttpURLConnection conn = null;
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        PageModel pm = new PageModel();
        pm.setCurrentPage(page);
        pm = dao.queryFawen(pm);
        //总的记录数
        record = pm.getTotalRecord();
        //总页数
        total = pm.getTotalPage();//total:总页数
        list = pm.getList();
        if (list.size() >0) {
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSONPage(list, total, page, "success", "发文精粹列表查询成功"));
        } else {
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "fail", "发文精粹列表查询失败"));
        }
    }

    //通讯录接口
    //http://localhost:8080/hh/gain_Address_list.action?parayId=40280a816859f2c1016859fb72c20033
    public void gain_Address_list() throws Exception {
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        HttpURLConnection conn = null;
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        String result = doPost("http://app.shuhai.cc/isms/manager/party/getCorporation/"+ parayId, "");
        System.out.println(result + "====123456");
        if(result == null){
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "fail", "无数据，请重新刷新页面。"));
        }else{
            JSONObject jsonObject = JSONObject.fromObject(result);
            String resultStr = jsonObject.toString();
            JsonParser jp = new JsonParser();
            //将json字符串转化成json对象
            JsonObject jo = jp.parse(resultStr).getAsJsonObject();
            String id = jo.get("object").getAsJsonObject().get("id").getAsString();//获取企业的object实体里的id
            String all_tongxunlist = doPost("http://app.shuhai.cc/isms/manager/party/all/" + id, "");
            System.out.println(all_tongxunlist);
            JSONObject jo_ = JSONObject.fromObject(all_tongxunlist);
            JSONArray rows = jo_.getJSONArray("rows");
            TongxunDao dao = new TongxunDao();
            TongxunModel model = new TongxunModel();
            List<TongxunModel> tongxunlist = new ArrayList<TongxunModel>();
            List<Sh_groupname> list_ = Sh_groupname.getAInitSh_groupnameList();
            Collections.sort(list_, new GroupnameComparetor());
            for (int i = 0; i < list_.size(); i++) {
                Sh_groupname kk = list_.get(i);
                String group_name = kk.getGroupName();
                TongxunModel mm = new TongxunModel();
                mm.setGroupName(group_name);
                tongxunlist.add(mm);
            }
            List<TongxunModel> list = new ArrayList<TongxunModel>();
            for (int j = 0; j < tongxunlist.size(); j++) {
                TongxunModel mm = tongxunlist.get(j);
                String groupName = mm.getGroupName();
                System.out.println(groupName + "====获取到的游标");
                //循环开始
                List<TongxunListModel> users = new ArrayList<TongxunListModel>();
                for (int i = 0; i < rows.size(); i++) {
                    String res = rows.getString(i);
                    JsonParser jps = new JsonParser();
                    JsonObject jos = jps.parse(res).getAsJsonObject();
                    String gain_id = jos.get("id").getAsString();//获取的id
                    String gain_name = jos.get("name").getAsString();//获取的姓名
                    String res_ = Serviceutil.converterToFirstSpell(gain_name);
                    if (res_.length() > 0) {
                        String zhuanhua_res = res_.substring(0, 1);

                        if (groupName.equals(zhuanhua_res)) {
                            System.out.println("==获取到的id==" + gain_id + "==获取到的姓名==" + gain_name + "==获取到的首字母是==" + zhuanhua_res);
                            TongxunListModel tongxunListModel = new TongxunListModel();
                            tongxunListModel.setId(gain_id);
                            tongxunListModel.setName(gain_name);
                            users.add(tongxunListModel);
                        }
                    } else {
                        logger.info("不做任何操作，STOP");
                    }
                }

                if (users.size() > 0) {
                    mm.setGroupName(groupName);
                    mm.setUsers(users);
                    list.add(mm);
                }
            }
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(list, "success", "通讯录列表查询成功"));
        }
    }

    //通讯录详情接口旧的
    //http://localhost:8080/hh/gain_Address_listId.action?id=40280a81681e33ce01681e33f5240000&parayId=40280a816859f2c1016859fb72c20033&username=高俊
    public void gain_Address_listId() throws Exception {
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        HttpURLConnection conn = null;
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        TongxunIdModel model = new TongxunIdModel();
        List<PhoneModel> phone_list = new ArrayList<PhoneModel>();
        String result = doPost("http://app.shuhai.cc/isms/manager/party/contact/"+id, "");
        System.out.println(result);
        JSONObject jo_ = JSONObject.fromObject(result);
        JSONArray rows = jo_.getJSONArray("rows");
        for (int i = 0; i < rows.size(); i++) {
            String res = rows.getString(i);
            JsonParser jps = new JsonParser();
            JsonObject jos = jps.parse(res).getAsJsonObject();
            String gain_contactNumber = jos.get("contactNumber").getAsString();//获取的手机号
            String gain_purposeName = jos.get("purposeName").getAsString();//获取的手机类型
            System.out.println(gain_contactNumber + "====" + gain_purposeName);
            PhoneModel mm = new PhoneModel();
            mm.setPhonenum(gain_contactNumber);
            mm.setPhonetype(gain_purposeName);
            phone_list.add(mm);
            model.setPhone_list(phone_list);
        }
        model.setName(username);
        CommModel mg_ = dao.queryO(id);
        if(mg_ != null){
            if("PARTY_GROUP".equals(mg_.getResult()) || "DEPARTMENT".equals(mg_.getResult())){
                model.setImg_url("http://www.ousoft.net/hh/txurl/corp.png");//部门
            }else if("PERSON".equals(mg_.getResult())){
                model.setImg_url("http://www.ousoft.net/hh/txurl/person.png");//个人
            }else if("CORPORATION".equals(mg_.getResult())){
                model.setImg_url("http://www.ousoft.net/hh/txurl/company.png");//公司
            }
        }
        JsonParser jp = new JsonParser();
        CloseableHttpClient httpclient_0 = HttpClients.createDefault();
        HttpPost httpPost_0 = new HttpPost("http://app.shuhai.cc/isms/manager/party/getParent/" + parayId);// 创建httpPost
        httpPost_0.setHeader("Accept", "application/json");
        httpPost_0.setHeader("Content-Type", "application/json");
        String charSet_0 = "UTF-8";
        StringEntity entity_0 = new StringEntity("", charSet_0);
        httpPost_0.setEntity(entity_0);
        CloseableHttpResponse response_0 = null;
        String id_ss = "";
        try {
            response_0 = httpclient_0.execute(httpPost_0);
            StatusLine status = response_0.getStatusLine();
            int state = status.getStatusCode();
            System.out.println(state + "=====");
            if (state == HttpStatus.SC_OK) {
                HttpEntity responseEntity_0 = response_0.getEntity();
                String jsonString = EntityUtils.toString(responseEntity_0);
                JSONObject jsonObject_2 = JSONObject.fromObject(jsonString);
                String resultStr_2 = jsonObject_2.toString();
                JsonParser jp_2 = new JsonParser();
                JsonObject jo_2 = jp.parse(resultStr_2).getAsJsonObject();
                JsonObject jo = jp.parse(resultStr_2).getAsJsonObject();
        String corp_name = jo.get("object").getAsJsonObject().get("name").getAsString();
                id_ss = jo.get("object").getAsJsonObject().get("id").getAsString();
                model.setCorp_name(corp_name);
            } else {
                logger.error("请求返回:" + state + "(" + "http://app.shuhai.cc/isms/manager/party/getParent/" + parayId + ")");
                model.setCorp_name("");
            }
        } finally {
            if (response_0 != null) {
                try {
                    response_0.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            try {
                httpclient_0.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        logger.info("========================分水岭==========================");
        //String result_two = doPost("http://app.shuhai.cc/isms/manager/party/getParent/" + id_ss, "");

        CloseableHttpClient httpclient = HttpClients.createDefault();
        HttpPost httpPost = new HttpPost("http://app.shuhai.cc/isms/manager/party/getParent/" + id_ss);// 创建httpPost
        httpPost.setHeader("Accept", "application/json");
        httpPost.setHeader("Content-Type", "application/json");
        String charSet = "UTF-8";
        StringEntity entity = new StringEntity("", charSet);
        httpPost.setEntity(entity);
        CloseableHttpResponse response_ = null;
        try {
            response_ = httpclient.execute(httpPost);
            StatusLine status = response_.getStatusLine();
            int state = status.getStatusCode();
            System.out.println(state + "=====");
            if (state == HttpStatus.SC_OK) {
                HttpEntity responseEntity = response_.getEntity();
                String jsonString = EntityUtils.toString(responseEntity);
                JSONObject jsonObject_2 = JSONObject.fromObject(jsonString);
                String resultStr_2 = jsonObject_2.toString();
                JsonParser jp_2 = new JsonParser();
                JsonObject jo_2 = jp.parse(resultStr_2).getAsJsonObject();
                String company_name = jo_2.get("object").getAsJsonObject().get("name").getAsString();
                model.setCompany_name(company_name);
                model.setStr(company_name + "|"+model.getCorp_name());
            } else {
                logger.error("请求返回:" + state + "(" + "http://app.shuhai.cc/isms/manager/party/getParent/" + id_ss + ")");
                model.setCompany_name("");
                model.setStr(model.getCorp_name());
            }
        } finally {
            if (response_ != null) {
                try {
                    response_.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            try {
                httpclient.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(model, "success", "通讯录详情初始化数据成功"));
    }

    //新的
    //http://localhost:8080/hh/gain_Address_listId.action?id=40280a81681e33ce01681e33f5240000&parayId=40280a816859f2c1016859fb72c20033&username=高俊
    public void gain_Address_listId2() throws Exception {
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        HttpURLConnection conn = null;
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        TongxunIdModel model = new TongxunIdModel();
        List<PhoneModel> phone_list = new ArrayList<PhoneModel>();
        //查询手机号
        List<PhoneModel> mm = dao.queryPhone(id);
        model.setPhone_list(mm);
        model.setName(username);
        CommModel mg_ = dao.queryO(id);
        if (mg_ != null) {
            if ("PARTY_GROUP".equals(mg_.getResult()) || "DEPARTMENT".equals(mg_.getResult())) {
                model.setImg_url("https://wxapp.shuhai.cc/hh/txurl/corp.png");//部门
            } else if ("PERSON".equals(mg_.getResult())) {
                model.setImg_url("https://wxapp.shuhai.cc/hh/txurl/person.png");//个人
            } else if ("CORPORATION".equals(mg_.getResult())) {
                model.setImg_url("https://wxapp.shuhai.cc/hh/txurl/company.png");//公司
            }
        }

        PhoneModel res_g = dao.queryCorpOrCompany(id);
        if (res_g != null) {
            String company = res_g.getPhonenum(); //公司
            model.setCompany_name(company);
        } else {
            model.setCompany_name("");
        }

        PhoneModel res_l = dao.queryCorpOrCompany(id);
        if (res_l != null) {
            String corp = res_l.getPhonetype(); //部门
            model.setCorp_name(corp);
        } else {
            model.setCorp_name("");
        }
        objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(model, "success", "通讯录详情初始化数据成功"));
    }

    //工资查询接口
    //http://localhost:8080/hh/querySalary.action?parayId=40280a816859f2c1016859fb72c20033&months=2019年1月
    public void querySalary() throws Exception {
        System.out.println("拿到的团体id："+parayId+ ",拿到的日期："+months);
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        HttpURLConnection conn = null;
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        String change = "";
        if(months.equals("")){
            change = "";
        }else{
            change = months;
        }
        SalaryModel model = new SalaryModel();
        List<S_Model> lists_ = new ArrayList<S_Model>();
        long time = System.currentTimeMillis();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年M月");
        change = sdf.format(time);
        //修改开始
        String result_0 = doPost("http://app.shuhai.cc/isms/manager/employeewages/query/" + parayId, change);
        System.out.println(result_0);
        JSONObject jo_0 = JSONObject.fromObject(result_0);
        JSONArray rows_0 = jo_0.getJSONArray("rows");
        SalaryModel model_0 = new SalaryModel();
        List<S_Model> lists_0 = new ArrayList<S_Model>();
        if (rows_0.size() > 0) {
            logger.info("当前月无数据");
            for (int i = 0; i < rows_0.size(); i++) {
                String res = rows_0.getString(i);
                JsonParser jps_0 = new JsonParser();
                JsonObject jos_0 = jps_0.parse(res).getAsJsonObject();
                String gain_months = jos_0.get("months").getAsString();//日期
                String gain_Name = jos_0.get("name").getAsString();//姓名
//                System.out.println(gain_months + "==获取到的日期和姓名==" + gain_Name);
                //获取lists集合中的项目名称和金额
                JsonArray lists_f = jos_0.get("lists").getAsJsonArray();
                for (int j = 0; j < lists_f.size(); j++) {
                    //System.out.println("获取到的lists集合里的值：" + lists.get(j));
                    JsonArray gain_lists_0 = lists_f.get(j).getAsJsonArray();
                    if (gain_lists_0.size() > 0) {
                        JsonElement one_0 = gain_lists_0.get(0);
                        JsonElement two_0 = gain_lists_0.get(1);
                        System.out.println(one_0.toString() + "=====" + two_0.toString());
                        S_Model s_0 = new S_Model();
                        s_0.setMoney(two_0.toString());
                        s_0.setProject_name(one_0.toString());
                        lists_0.add(s_0);
                    }
                }
                //有数据赋值开始
                model.setName(gain_Name);
                model.setMonths(gain_months);
                model.setLists(lists_0);
                //有数据赋值结束
            }
        } else {
            logger.info("显示上月无数据");
            SimpleDateFormat format = new SimpleDateFormat("yyyy年M月");
            Calendar c = Calendar.getInstance();
            c.setTime(new Date());
            c.add(Calendar.MONTH, -1);
            Date m = c.getTime();
            change = format.format(m);
            System.out.println("打印上月的数据"+ change+"=====parayId==="+ parayId);
            String result_1 = doPost("http://app.shuhai.cc/isms/manager/employeewages/query/" + parayId, change);
            System.out.println(result_1);
            JSONObject jo_1 = JSONObject.fromObject(result_1);
            JSONArray rows_1 = jo_1.getJSONArray("rows");
            SalaryModel model_1 = new SalaryModel();
            if (rows_1.size() > 0) {
                for (int i = 0; i < rows_1.size(); i++) {
                    String res = rows_1.getString(i);
                    JsonParser jps_1 = new JsonParser();
                    JsonObject jos_1 = jps_1.parse(res).getAsJsonObject();
                    String gain_months = jos_1.get("months").getAsString();//日期
                    String gain_Name = jos_1.get("name").getAsString();//姓名
//                System.out.println(gain_months + "==获取到的日期和姓名==" + gain_Name);
                    //获取lists集合中的项目名称和金额
                    JsonArray lists_f = jos_1.get("lists").getAsJsonArray();
                    for (int j = 0; j < lists_f.size(); j++) {
                        //System.out.println("获取到的lists集合里的值：" + lists.get(j));
                        JsonArray gain_lists_0 = lists_f.get(j).getAsJsonArray();
                        if (gain_lists_0.size() > 0) {
                            JsonElement one_0 = gain_lists_0.get(0);
                            JsonElement two_0 = gain_lists_0.get(1);
                            System.out.println(one_0.toString() + "=====" + two_0.toString());
                            S_Model s_0 = new S_Model();
                            s_0.setMoney(two_0.toString());
                            s_0.setProject_name(one_0.toString());
                            lists_0.add(s_0);
                        }
                    }
                    model.setName(gain_Name);
                    model.setMonths(gain_months);
                    model.setLists(lists_0);
                }
            }else{
                logger.info("显示上月1");
                SimpleDateFormat format1 = new SimpleDateFormat("yyyy年M月");
                Calendar c1 = Calendar.getInstance();
                c1.setTime(new Date());
                c1.add(Calendar.MONTH, -2);
                Date m1 = c1.getTime();
                change = format1.format(m1);
                System.out.println("打印上月的数据" + change + "=====parayId===" + parayId);
                String result_2 = doPost("http://app.shuhai.cc/isms/manager/employeewages/query/" + parayId, change);
                System.out.println(result_2);
                JSONObject jo_2 = JSONObject.fromObject(result_2);
                JSONArray rows_2 = jo_2.getJSONArray("rows");
                SalaryModel model_2 = new SalaryModel();
                if (rows_2.size() > 0) {
                    for (int i = 0; i < rows_2.size(); i++) {
                        String res2 = rows_2.getString(i);
                        JsonParser jps_2 = new JsonParser();
                        JsonObject jos_2 = jps_2.parse(res2).getAsJsonObject();
                        String gain_months2 = jos_2.get("months").getAsString();//日期
                        String gain_Name2 = jos_2.get("name").getAsString();//姓名
//                System.out.println(gain_months + "==获取到的日期和姓名==" + gain_Name);
                        //获取lists集合中的项目名称和金额
                        JsonArray lists_f2 = jos_2.get("lists").getAsJsonArray();
                        for (int j = 0; j < lists_f2.size(); j++) {
                            //System.out.println("获取到的lists集合里的值：" + lists.get(j));
                            JsonArray gain_lists_2 = lists_f2.get(j).getAsJsonArray();
                            if (gain_lists_2.size() > 0) {
                                JsonElement one_2 = gain_lists_2.get(0);
                                JsonElement two_2 = gain_lists_2.get(1);
                                System.out.println(one_2.toString() + "=====" + two_2.toString());
                                S_Model s_2 = new S_Model();
                                s_2.setMoney(two_2.toString());
                                s_2.setProject_name(one_2.toString());
                                lists_0.add(s_2);
                            }
                        }

                        model.setName(gain_Name2);
                        model.setMonths(gain_months2);
                        model.setLists(lists_0);
                    }
            }else{
                    logger.info("显示上月2");
                    SimpleDateFormat format2 = new SimpleDateFormat("yyyy年M月");
                    Calendar c2 = Calendar.getInstance();
                    c2.setTime(new Date());
                    c2.add(Calendar.MONTH, -3);
                    Date m2 = c2.getTime();
                    change = format2.format(m2);
                    System.out.println("打印上月的数据" + change + "=====parayId===" + parayId);
                    String result_3 = doPost("http://app.shuhai.cc/isms/manager/employeewages/query/" + parayId, change);
                    System.out.println(result_3);
                    JSONObject jo_3 = JSONObject.fromObject(result_3);
                    JSONArray rows_3 = jo_3.getJSONArray("rows");
                    SalaryModel model_3 = new SalaryModel();
                    if (rows_3.size() > 0) {
                        for (int i = 0; i < rows_3.size(); i++) {
                            String res3 = rows_3.getString(i);
                            JsonParser jps_3 = new JsonParser();
                            JsonObject jos_3 = jps_3.parse(res3).getAsJsonObject();
                            String gain_months3 = jos_3.get("months").getAsString();//日期
                            String gain_Name3 = jos_3.get("name").getAsString();//姓名
//                System.out.println(gain_months + "==获取到的日期和姓名==" + gain_Name);
                            //获取lists集合中的项目名称和金额
                            JsonArray lists_f3 = jos_3.get("lists").getAsJsonArray();
                            for (int j = 0; j < lists_f3.size(); j++) {
                                //System.out.println("获取到的lists集合里的值：" + lists.get(j));
                                JsonArray gain_lists_3 = lists_f3.get(j).getAsJsonArray();
                                if (gain_lists_3.size() > 0) {
                                    JsonElement one_3 = gain_lists_3.get(0);
                                    JsonElement two_3 = gain_lists_3.get(1);
                                    System.out.println(one_3.toString() + "=====" + two_3.toString());
                                    S_Model s_3 = new S_Model();
                                    s_3.setMoney(two_3.toString());
                                    s_3.setProject_name(one_3.toString());
                                    lists_0.add(s_3);
                                }
                            }
                            model.setName(gain_Name3);
                            model.setMonths(gain_months3);
                            model.setLists(lists_0);
                        }
                    }else{
                        logger.info("显示上月3");
                        SimpleDateFormat format3 = new SimpleDateFormat("yyyy年M月");
                        Calendar c3 = Calendar.getInstance();
                        c3.setTime(new Date());
                        c3.add(Calendar.MONTH, -4);
                        Date m3 = c3.getTime();
                        change = format3.format(m3);
                        System.out.println("打印上月的数据" + change + "=====parayId===" + parayId);
                        String result_4 = doPost("http://app.shuhai.cc/isms/manager/employeewages/query/" + parayId, change);
                        System.out.println(result_4);
                        JSONObject jo_4 = JSONObject.fromObject(result_4);
                        JSONArray rows_4 = jo_4.getJSONArray("rows");
                        SalaryModel model_4 = new SalaryModel();
                        if (rows_4.size() > 0) {
                            for (int i = 0; i < rows_4.size(); i++) {
                                String res4 = rows_4.getString(i);
                                JsonParser jps_4 = new JsonParser();
                                JsonObject jos_4 = jps_4.parse(res4).getAsJsonObject();
                                String gain_months4 = jos_4.get("months").getAsString();//日期
                                String gain_Name4 = jos_4.get("name").getAsString();//姓名
//                System.out.println(gain_months + "==获取到的日期和姓名==" + gain_Name);
                                //获取lists集合中的项目名称和金额
                                JsonArray lists_f4 = jos_4.get("lists").getAsJsonArray();
                                for (int j = 0; j < lists_f4.size(); j++) {
                                    //System.out.println("获取到的lists集合里的值：" + lists.get(j));
                                    JsonArray gain_lists_4 = lists_f4.get(j).getAsJsonArray();
                                    if (gain_lists_4.size() > 0) {
                                        JsonElement one_4 = gain_lists_4.get(0);
                                        JsonElement two_4 = gain_lists_4.get(1);
                                        System.out.println(one_4.toString() + "=====" + two_4.toString());
                                        S_Model s_4 = new S_Model();
                                        s_4.setMoney(two_4.toString());
                                        s_4.setProject_name(one_4.toString());
                                        lists_0.add(s_4);
                                    }
                                }
                                model.setName(gain_Name4);
                                model.setMonths(gain_months4);
                                model.setLists(lists_0);
                            }
                        }else{
                            logger.info("显示上月4");
                            SimpleDateFormat format4 = new SimpleDateFormat("yyyy年M月");
                            Calendar c4 = Calendar.getInstance();
                            c4.setTime(new Date());
                            c4.add(Calendar.MONTH, -5);
                            Date m4 = c4.getTime();
                            change = format4.format(m4);
                            System.out.println("打印上月的数据" + change + "=====parayId===" + parayId);
                            String result_5 = doPost("http://app.shuhai.cc/isms/manager/employeewages/query/" + parayId, change);
                            System.out.println(result_5);
                            JSONObject jo_5 = JSONObject.fromObject(result_5);
                            JSONArray rows_5 = jo_5.getJSONArray("rows");
                            SalaryModel model_5 = new SalaryModel();
                            if (rows_5.size() > 0) {
                                for (int i = 0; i < rows_5.size(); i++) {
                                    String res5 = rows_5.getString(i);
                                    JsonParser jps_5 = new JsonParser();
                                    JsonObject jos_5 = jps_5.parse(res5).getAsJsonObject();
                                    String gain_months5 = jos_5.get("months").getAsString();//日期
                                    String gain_Name5 = jos_5.get("name").getAsString();//姓名
//                System.out.println(gain_months + "==获取到的日期和姓名==" + gain_Name);
                                    //获取lists集合中的项目名称和金额
                                    JsonArray lists_f5 = jos_5.get("lists").getAsJsonArray();
                                    for (int j = 0; j < lists_f5.size(); j++) {
                                        //System.out.println("获取到的lists集合里的值：" + lists.get(j));
                                        JsonArray gain_lists_5 = lists_f5.get(j).getAsJsonArray();
                                        if (gain_lists_5.size() > 0) {
                                            JsonElement one_5 = gain_lists_5.get(0);
                                            JsonElement two_5 = gain_lists_5.get(1);
                                            System.out.println(one_5.toString() + "=====" + two_5.toString());
                                            S_Model s_5 = new S_Model();
                                            s_5.setMoney(two_5.toString());
                                            s_5.setProject_name(one_5.toString());
                                            lists_0.add(s_5);
                                        }
                                    }
                                    model.setName(gain_Name5);
                                    model.setMonths(gain_months5);
                                    model.setLists(lists_0);
                                }
                            }else{
                                logger.info("显示上月5");
                                model.setName("");
                                model.setMonths("");
                                S_Model s = new S_Model();
                                s.setMoney("0");
                                s.setProject_name("无");
                                lists_.add(s);
                                model.setLists(lists_);
                            }
                        }
                    }
                }
        }
        }
        objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(model, "success", "查询工资接口初始化数据成功"));
    }

    //查询工资条搜索
    public void querySalary_ss() throws Exception {
        System.out.println("拿到的团体id：" + parayId + ",拿到的日期：" + months);
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        HttpURLConnection conn = null;
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        String change = "";
        if (months.equals("")) {
            change = "";
        } else {
            change = months;
        }
        SalaryModel model = new SalaryModel();
        List<S_Model> lists_ = new ArrayList<S_Model>();
            System.out.println("最终拿到的结果：" + change + ",最终拿到的长度：" + change.length());
            String result = doPost("http://app.shuhai.cc/isms/manager/employeewages/query/" + parayId, change);
            
            JSONObject jo_ = JSONObject.fromObject(result);
            JSONArray rows = jo_.getJSONArray("rows");
            
            System.out.println(result);
            if (rows.size() > 0) {
                for (int i = 0; i < rows.size(); i++) {
                    String res = rows.getString(i);
                    JsonParser jps = new JsonParser();
                    JsonObject jos = jps.parse(res).getAsJsonObject();
                    String gain_months = jos.get("months").getAsString();//日期
                    String gain_Name = jos.get("name").getAsString();//姓名
//                System.out.println(gain_months + "==获取到的日期和姓名==" + gain_Name);
                    //获取lists集合中的项目名称和金额
                    JsonArray lists = jos.get("lists").getAsJsonArray();
                    for (int j = 0; j < lists.size(); j++) {
                        JsonElement list_ = lists.get(j);
                        //System.out.println("获取到的lists集合里的值：" + lists.get(j));
                        JsonArray gain_lists = lists.get(j).getAsJsonArray();
                        if (gain_lists.size() > 0) {
                            JsonElement one = gain_lists.get(0);
                            JsonElement two = gain_lists.get(1);
                            System.out.println(one.toString() + "=====" + two.toString());
                            S_Model s = new S_Model();
                            s.setMoney(two.toString());
                            s.setProject_name(one.toString());
                            lists_.add(s);
                        }
                    }
                    //有数据赋值开始
                    model.setName(gain_Name);
                    model.setMonths(gain_months);
                    model.setLists(lists_);
                    //有数据赋值结束
                }
            } else {
                model.setName("");
                model.setMonths("");
                S_Model s = new S_Model();
                s.setMoney("0");
                s.setProject_name("无");
                lists_.add(s);
                model.setLists(lists_);
            }
        objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(model, "success", "查询工资接口初始化数据成功"));
    }

    //转化时间接口
    public void changeTime() throws Exception {
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        HttpURLConnection conn = null;
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        CommModel model = new CommModel();
        String year = c_time.substring(0, 4);
        String month = c_time.substring(5, 7);
        model.setResult(year+"年"+ Integer.parseInt(month)+"月");
        objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(model, "success", "转化时间接口数据成功"));
    }

    public void gian_Username() throws Exception {
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        HttpURLConnection conn = null;
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        CommModel model = new CommModel();
        String result = doPost("http://app.shuhai.cc/isms/manager/party/getParty/" + parayId, "");
        JSONObject jsonObject = JSONObject.fromObject(result);
        String resultStr = jsonObject.toString();
        JsonParser jp = new JsonParser();
        //将json字符串转化成json对象
        JsonObject jo = jp.parse(resultStr).getAsJsonObject();
        String name = jo.get("object").getAsJsonObject().get("name").getAsString();
        model.setResult(name);
        objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(model, "success", "获取用户名称数据成功"));
    }

    public void gain_Url() throws Exception {
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        HttpURLConnection conn = null;
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        CommModel model = new CommModel();
        CommModel mm = dao.gain_Url(id);
        if(mm != null){
            model.setResult(mm.getResult());
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(model, "success", "获取URL数据成功"));
        }else{
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(model, "fail", "获取URL数据失败"));
        }
    }

    //测试通讯录第二版接口
    public void gain_Address_list_two() throws Exception {
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        HttpURLConnection conn = null;
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        String result = doPost("http://app.shuhai.cc/isms/manager/party/getCorporation/" + parayId, "");
        System.out.println(result + "====123456");
        if (result == null) {
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "fail", "无数据，请重新刷新页面。"));
        } else {
            JSONObject jsonObject = JSONObject.fromObject(result);
            String resultStr = jsonObject.toString();
            JsonParser jp = new JsonParser();
            //将json字符串转化成json对象
            JsonObject jo = jp.parse(resultStr).getAsJsonObject();
            String id = jo.get("object").getAsJsonObject().get("id").getAsString();//获取企业的object实体里的id
            String all_tongxunlist = doPost("http://app.shuhai.cc/isms/manager/party/all/" + id, "");
            System.out.println(all_tongxunlist);
            JSONObject jo_ = JSONObject.fromObject(all_tongxunlist);
            JSONArray rows = jo_.getJSONArray("rows");
            TongxunDao dao = new TongxunDao();
            TongxunModel model = new TongxunModel();
            List<Tongxun_twoModel> tongxunlist = new ArrayList<Tongxun_twoModel>();
            List<Sh_groupname> list_ = Sh_groupname.getAInitSh_groupnameList();
            Collections.sort(list_, new GroupnameComparetor());
            for (int i = 0; i < list_.size(); i++) {
                Sh_groupname kk = list_.get(i);
                String group_name = kk.getGroupName();
                Tongxun_twoModel mm = new Tongxun_twoModel();
                mm.setId(group_name);
                tongxunlist.add(mm);
            }
            List<Tongxun_twoModel> list = new ArrayList<Tongxun_twoModel>();
            for (int j = 0; j < tongxunlist.size(); j++) {
                Tongxun_twoModel mm = tongxunlist.get(j);
                String groupName = mm.getId();
                System.out.println(groupName + "====获取到的游标");
                //循环开始
                List<Tongxun_twoListModel> users = new ArrayList<Tongxun_twoListModel>();
                for (int i = 0; i < rows.size(); i++) {
                    String res = rows.getString(i);
                    JsonParser jps = new JsonParser();
                    JsonObject jos = jps.parse(res).getAsJsonObject();
                    String gain_id = jos.get("id").getAsString();//获取的id
                    String gain_name = jos.get("name").getAsString();//获取的姓名
                    String type = jos.get("type").getAsString();//获取的类型
                    String res_ = Serviceutil.converterToFirstSpell(gain_name);
                    if (res_.length() > 0) {
                        String zhuanhua_res = res_.substring(0, 1);

                        if (groupName.equals(zhuanhua_res)) {
                            //System.out.println("==获取到的id==" + gain_id + "==获取到的姓名==" + gain_name + "==获取到的首字母是==" + zhuanhua_res + "==类型=="+type);
                            Tongxun_twoListModel tongxunListModel = new Tongxun_twoListModel();
                            tongxunListModel.setId(gain_id);
                              tongxunListModel.setName(gain_name);
                            users.add(tongxunListModel);
                        }
                    } else {
                        logger.info("不做任何操作，STOP");
                    }
                }
                for (int u = 0; u < users.size() - 1; u++) {
                    for (int f = users.size() - 1; f > u; f--) {
                        if (users.get(f).getName() == users.get(u).getName()) {
                            users.remove(f);
                        }
                    }
                }
                for (int i = 0; i < users.size(); i++) {

                    System.out.println("姓名："+ users.get(i).getName());
                }
                    mm.setId(groupName);
                    mm.setItems(users);
                    if(users.size() >0){
                        mm.setEnabled(true);
                    }else{
                        mm.setEnabled(false);
                    }
                    list.add(mm);
            }
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(list, "success", "通讯录列表查询成功"));
        }
    }

    public void gain_Address_list_ss() throws Exception {
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        HttpURLConnection conn = null;
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        String result = doPost("http://app.shuhai.cc/isms/manager/party/getCorporation/" + parayId, "");
        logger.info("返回结果："+ result);
        if (result == null) {
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "fail", "无数据"));
        } else {
            if(username.equals("") && ("").equals(username)){
                //为空也返回数据
                //System.out.println("为空也返回数据");
                JSONObject jsonObject = JSONObject.fromObject(result);
                String resultStr = jsonObject.toString();
                JsonParser jp = new JsonParser();
                //将json字符串转化成json对象
                JsonObject jo = jp.parse(resultStr).getAsJsonObject();
                String id = jo.get("object").getAsJsonObject().get("id").getAsString();//获取企业的object实体里的id(集团id)
                String all_tongxunlist = doPost("http://app.shuhai.cc/isms/manager/party/all/" + id, "");//所有
                System.out.println(all_tongxunlist);
                JSONObject jo_ = JSONObject.fromObject(all_tongxunlist);
                JSONArray rows = jo_.getJSONArray("rows");
                TongxunDao dao = new TongxunDao();
                TongxunModel model = new TongxunModel();
                List<Tongxun_twoModel> tongxunlist = new ArrayList<Tongxun_twoModel>();
                List<Sh_groupname> list_ = Sh_groupname.getAInitSh_groupnameList();
                Collections.sort(list_, new GroupnameComparetor());
                for (int i = 0; i < list_.size(); i++) {
                    Sh_groupname kk = list_.get(i);
                    String group_name = kk.getGroupName();
                    Tongxun_twoModel mm = new Tongxun_twoModel();
                    mm.setId(group_name);
                    tongxunlist.add(mm);
                }
                List<Tongxun_twoModel> list = new ArrayList<Tongxun_twoModel>();
                for (int j = 0; j < tongxunlist.size(); j++) {
                    Tongxun_twoModel mm = tongxunlist.get(j);
                    String groupName = mm.getId();
                    System.out.println(groupName + "====获取到的游标");
                    //循环开始
                    List<Tongxun_twoListModel> users = new ArrayList<Tongxun_twoListModel>();
                    for (int i = 0; i < rows.size(); i++) {
                        String res = rows.getString(i);
                        JsonParser jps = new JsonParser();
                        JsonObject jos = jps.parse(res).getAsJsonObject();
                        String gain_id = jos.get("id").getAsString();//获取的id
                        String gain_name = jos.get("name").getAsString();//获取的姓名
                        String res_ = Serviceutil.converterToFirstSpell(gain_name);
                        if (res_.length() > 0) {
                            String zhuanhua_res = res_.substring(0, 1);

                            if (groupName.equals(zhuanhua_res)) {
                                System.out.println("==获取到的id==" + gain_id + "==获取到的姓名==" + gain_name + "==获取到的首字母是==" + zhuanhua_res);
                                Tongxun_twoListModel tongxunListModel = new Tongxun_twoListModel();
                                tongxunListModel.setId(gain_id);
                                tongxunListModel.setName(gain_name);
                                users.add(tongxunListModel);
                            }
                        } else {
                            logger.info("不做任何操作，STOP");
                        }
                    }

                    mm.setId(groupName);
                    mm.setItems(users);
                    if (users.size() > 0) {
                        mm.setEnabled(true);
                    } else {
                        mm.setEnabled(false);
                    }
                    list.add(mm);
                }
                objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(list, "success", "通讯录列表查询成功"));
            }else{
                //System.out.println("不为空开始模糊搜索出通讯录用户信息");
                //不为空开始模糊搜索出通讯录用户信息
                JSONObject jsonObject = JSONObject.fromObject(result);
                String resultStr = jsonObject.toString();
                JsonParser jp = new JsonParser();
                //将json字符串转化成json对象
                JsonObject jo = jp.parse(resultStr).getAsJsonObject();
                String id = jo.get("object").getAsJsonObject().get("id").getAsString();//获取企业的object实体里的id
                String all_tongxunlist = doPost("http://app.shuhai.cc/isms/manager/party/query/" + id, username);//集团
                System.out.println(all_tongxunlist);
                JSONObject jo_ = JSONObject.fromObject(all_tongxunlist);
                JSONArray rows = jo_.getJSONArray("rows");
                TongxunDao dao = new TongxunDao();
                TongxunModel model = new TongxunModel();
                List<Tongxun_twoModel> tongxunlist = new ArrayList<Tongxun_twoModel>();
                List<Sh_groupname> list_ = Sh_groupname.getAInitSh_groupnameList();
                Collections.sort(list_, new GroupnameComparetor());
                for (int i = 0; i < list_.size(); i++) {
                    Sh_groupname kk = list_.get(i);
                    String group_name = kk.getGroupName();
                    Tongxun_twoModel mm = new Tongxun_twoModel();
                    mm.setId(group_name);
                    tongxunlist.add(mm);
                }
                List<Tongxun_twoModel> list = new ArrayList<Tongxun_twoModel>();
                for (int j = 0; j < tongxunlist.size(); j++) {
                    Tongxun_twoModel mm = tongxunlist.get(j);
                    String groupName = mm.getId();
                    System.out.println(groupName + "====获取到的游标");
                    //循环开始
                    List<Tongxun_twoListModel> users = new ArrayList<Tongxun_twoListModel>();
                    for (int i = 0; i < rows.size(); i++) {
                        String res = rows.getString(i);
                        JsonParser jps = new JsonParser();
                        JsonObject jos = jps.parse(res).getAsJsonObject();
                        String gain_id = jos.get("id").getAsString();//获取的id
                        String gain_name = jos.get("name").getAsString();//获取的姓名
                        String res_ = Serviceutil.converterToFirstSpell(gain_name);
                        if (res_.length() > 0) {
                            String zhuanhua_res = res_.substring(0, 1);

                            if (groupName.equals(zhuanhua_res)) {
                                System.out.println("==获取到的id==" + gain_id + "==获取到的姓名==" + gain_name + "==获取到的首字母是==" + zhuanhua_res);
                                Tongxun_twoListModel tongxunListModel = new Tongxun_twoListModel();
                                tongxunListModel.setId(gain_id);
                                tongxunListModel.setName(gain_name);
                                users.add(tongxunListModel);
                            }
                        } else {
                            logger.info("不做任何操作，STOP");
                        }
                    }

                    mm.setId(groupName);
                    mm.setItems(users);
                    if (users.size() > 0) {
                        mm.setEnabled(true);
                    } else {
                        mm.setEnabled(false);
                    }
                    list.add(mm);
                }
                objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(list, "success", "通讯录列表查询成功"));
            }
        }
    }

    //通讯录初始化接口第二版最新(2019年4月3日)
    public void gain_Address_list_twoTest() throws Exception {
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        HttpURLConnection conn = null;
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
            String all_tongxunlist = doPost("http://app.shuhai.cc/isms/manager/party/all/" + id, "");
            System.out.println(all_tongxunlist);
            JSONObject jo_ = JSONObject.fromObject(all_tongxunlist);
            JSONArray rows = jo_.getJSONArray("rows");
            TongxunDao dao = new TongxunDao();
            TongxunModel model = new TongxunModel();
            List<Tongxun_twoModel> tongxunlist = new ArrayList<Tongxun_twoModel>();
            List<Sh_groupname> list_ = Sh_groupname.getAInitSh_groupnameList();
            Collections.sort(list_, new GroupnameComparetor());
            for (int i = 0; i < list_.size(); i++) {
                Sh_groupname kk = list_.get(i);
                String group_name = kk.getGroupName();
                Tongxun_twoModel mm = new Tongxun_twoModel();
                mm.setId(group_name);
                tongxunlist.add(mm);
            }
            JSONArray jsons = new JSONArray();
            for (int i = 0; i < rows.size(); i++) {
                String res = rows.getString(i);
                JsonParser jps = new JsonParser();
                JsonObject jos = jps.parse(res).getAsJsonObject();
                String gain_id = jos.get("id").getAsString();//获取的id
                String gain_name = jos.get("name").getAsString();//获取的姓名
                String type = jos.get("type").getAsString();//获取的类型
                String parentId = jos.get("parentId").getAsString();//父ID
                String res_ = Serviceutil.converterToFirstSpell(gain_name);
                if ((!gain_id.equals(party_id) && !type.equals("PARTY_GROUP")) | parentId.equals(id)) {
                        jsons.add(res);
                }
            }
            List<Tongxun_twoModel> list = new ArrayList<Tongxun_twoModel>();
            for (int j = 0; j < tongxunlist.size(); j++) {
                Tongxun_twoModel mm = tongxunlist.get(j);
                String groupName = mm.getId();
                System.out.println(groupName + "====获取到的游标");
                List<Tongxun_twoListModel> users = new ArrayList<Tongxun_twoListModel>();
                    for (int m = 0; m < jsons.size(); m++) {
                        String res1 = jsons.getString(m);
                        JsonParser jps1 = new JsonParser();
                        JsonObject jos1 = jps1.parse(res1).getAsJsonObject();
                        String gain_id1 = jos1.get("id").getAsString();//获取的id
                        String gain_name1 = jos1.get("name").getAsString();//获取的姓名
                        String type1 = jos1.get("type").getAsString();//获取的类型
                        String parentId1 = jos1.get("parentId").getAsString();//父ID
                        String res_1 = Serviceutil.converterToFirstSpell(gain_name1);
                        if (res_1.length() > 0) {
                            String zhuanhua_res = res_1.substring(0, 1);
                            if (groupName.equals(zhuanhua_res)) {
                                System.out.println("==获取到的id==" + gain_id1 + "==获取到的姓名==" + gain_name1 + "==获取到的首字母是==" + zhuanhua_res);
                                Tongxun_twoListModel tongxunListModel = new Tongxun_twoListModel();
                                tongxunListModel.setId(gain_id1);
                                tongxunListModel.setName(gain_name1);
                                users.add(tongxunListModel);
                                mm.setItems(users);
                            }
                        } else {
                            logger.info("不做任何操作，STOP");
                        }
                    }
                if (users.size() > 0) {
                    mm.setEnabled(true);
                } else {
                    mm.setEnabled(false);
                }
                list.add(mm);
            }
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(list, "success", "通讯录列表查询成功"));
    }

    public void gain_Address_list_ssTest() throws Exception {
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        HttpURLConnection conn = null;
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        {
            if (username.equals("") && ("").equals(username)) {
                String all_tongxunlist = doPost("http://app.shuhai.cc/isms/manager/party/all/" + id, username);
                System.out.println(all_tongxunlist);
                JSONObject jo_ = JSONObject.fromObject(all_tongxunlist);
                JSONArray rows = jo_.getJSONArray("rows");
                TongxunDao dao = new TongxunDao();
                TongxunModel model = new TongxunModel();
                List<Tongxun_twoModel> tongxunlist = new ArrayList<Tongxun_twoModel>();
                List<Sh_groupname> list_ = Sh_groupname.getAInitSh_groupnameList();
                Collections.sort(list_, new GroupnameComparetor());
                for (int i = 0; i < list_.size(); i++) {
                    Sh_groupname kk = list_.get(i);
                    String group_name = kk.getGroupName();
                    Tongxun_twoModel mm = new Tongxun_twoModel();
                    mm.setId(group_name);
                    tongxunlist.add(mm);
                }
                JSONArray jsons = new JSONArray();
                for (int i = 0; i < rows.size(); i++) {
                    String res = rows.getString(i);
                    JsonParser jps = new JsonParser();
                    JsonObject jos = jps.parse(res).getAsJsonObject();
                    String gain_id = jos.get("id").getAsString();//获取的id
                    String gain_name = jos.get("name").getAsString();//获取的姓名
                    String type = jos.get("type").getAsString();//获取的类型
                    String parentId = jos.get("parentId").getAsString();//父ID
                    String res_ = Serviceutil.converterToFirstSpell(gain_name);
                    if ((!gain_id.equals(party_id) && !type.equals("PARTY_GROUP")) | parentId.equals(id)) {
                        jsons.add(res);
                    }
                }
                List<Tongxun_twoModel> list = new ArrayList<Tongxun_twoModel>();
                for (int j = 0; j < tongxunlist.size(); j++) {
                    Tongxun_twoModel mm = tongxunlist.get(j);
                    String groupName = mm.getId();
                    System.out.println(groupName + "====获取到的游标");
                    List<Tongxun_twoListModel> users = new ArrayList<Tongxun_twoListModel>();
                    for (int m = 0; m < jsons.size(); m++) {
                        String res1 = jsons.getString(m);
                        JsonParser jps1 = new JsonParser();
                        JsonObject jos1 = jps1.parse(res1).getAsJsonObject();
                        String gain_id1 = jos1.get("id").getAsString();//获取的id
                        String gain_name1 = jos1.get("name").getAsString();//获取的姓名
                        String type1 = jos1.get("type").getAsString();//获取的类型
                        String parentId1 = jos1.get("parentId").getAsString();//父ID
                        String res_1 = Serviceutil.converterToFirstSpell(gain_name1);
                        if (res_1.length() > 0) {
                            String zhuanhua_res = res_1.substring(0, 1);
                            if (groupName.equals(zhuanhua_res)) {
                                System.out.println("==获取到的id==" + gain_id1 + "==获取到的姓名==" + gain_name1 + "==获取到的首字母是==" + zhuanhua_res);
                                Tongxun_twoListModel tongxunListModel = new Tongxun_twoListModel();
                                tongxunListModel.setId(gain_id1);
                                tongxunListModel.setName(gain_name1);
                                users.add(tongxunListModel);
                                mm.setItems(users);
                            }
                        } else {
                            logger.info("不做任何操作，STOP");
                        }
                    }
                    if (users.size() > 0) {
                        mm.setEnabled(true);
                    } else {
                        mm.setEnabled(false);
                    }
                    list.add(mm);
                }
                objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(list, "success", "通讯录列表查询成功"));
            } else {
                String all_tongxunlist = doPost("http://app.shuhai.cc/isms/manager/party/query/" + id, username);
                System.out.println(all_tongxunlist);
                JSONObject jo_ = JSONObject.fromObject(all_tongxunlist);
                JSONArray rows = jo_.getJSONArray("rows");
                TongxunDao dao = new TongxunDao();
                TongxunModel model = new TongxunModel();
                List<Tongxun_twoModel> tongxunlist = new ArrayList<Tongxun_twoModel>();
                List<Sh_groupname> list_ = Sh_groupname.getAInitSh_groupnameList();
                Collections.sort(list_, new GroupnameComparetor());
                for (int i = 0; i < list_.size(); i++) {
                    Sh_groupname kk = list_.get(i);
                    String group_name = kk.getGroupName();
                    Tongxun_twoModel mm = new Tongxun_twoModel();
                    mm.setId(group_name);
                    tongxunlist.add(mm);
                }
                JSONArray jsons = new JSONArray();
                for (int i = 0; i < rows.size(); i++) {
                    String res = rows.getString(i);
                    JsonParser jps = new JsonParser();
                    JsonObject jos = jps.parse(res).getAsJsonObject();
                    String gain_id = jos.get("id").getAsString();//获取的id
                    String gain_name = jos.get("name").getAsString();//获取的姓名
                    String type = jos.get("type").getAsString();//获取的类型
                    String parentId = jos.get("parentId").getAsString();//父ID
                    String res_ = Serviceutil.converterToFirstSpell(gain_name);
                    if ((!gain_id.equals(party_id) && !type.equals("PARTY_GROUP")) | parentId.equals(id)) {
                        jsons.add(res);
                    }
                }
                List<Tongxun_twoModel> list = new ArrayList<Tongxun_twoModel>();
                for (int j = 0; j < tongxunlist.size(); j++) {
                    Tongxun_twoModel mm = tongxunlist.get(j);
                    String groupName = mm.getId();
                    System.out.println(groupName + "====获取到的游标");
                    List<Tongxun_twoListModel> users = new ArrayList<Tongxun_twoListModel>();
                    for (int m = 0; m < jsons.size(); m++) {
                        String res1 = jsons.getString(m);
                        JsonParser jps1 = new JsonParser();
                        JsonObject jos1 = jps1.parse(res1).getAsJsonObject();
                        String gain_id1 = jos1.get("id").getAsString();//获取的id
                        String gain_name1 = jos1.get("name").getAsString();//获取的姓名
                        String type1 = jos1.get("type").getAsString();//获取的类型
                        String parentId1 = jos1.get("parentId").getAsString();//父ID
                        String res_1 = Serviceutil.converterToFirstSpell(gain_name1);
                        if (res_1.length() > 0) {
                            String zhuanhua_res = res_1.substring(0, 1);
                            if (groupName.equals(zhuanhua_res)) {
                                System.out.println("==获取到的id==" + gain_id1 + "==获取到的姓名==" + gain_name1 + "==获取到的首字母是==" + zhuanhua_res);
                                Tongxun_twoListModel tongxunListModel = new Tongxun_twoListModel();
                                tongxunListModel.setId(gain_id1);
                                tongxunListModel.setName(gain_name1);
                                users.add(tongxunListModel);
                                mm.setItems(users);
                            }
                        } else {
                            logger.info("不做任何操作，STOP");
                        }
                    }
                    if (users.size() > 0) {
                        mm.setEnabled(true);
                    } else {
                        mm.setEnabled(false);
                    }
                    list.add(mm);
                }
                objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(list, "success", "通讯录列表查询成功"));
            }
        }
    }

    //发送短信接口
    public void sendSMS() throws Exception {
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        HttpURLConnection conn = null;
        System.out.println("______________短信开发对接口______________");
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        SMSModel model = new SMSModel();
        String result = doPost("http://app.shuhai.cc/shcmweb/service/phoneVerification/sendYZM?phone="+phone+"&signName=书海办公助手&TemplateCode=SMS_152282602&names=code", "");
        logger.info("调用发送短信接口返回结果："+result);
        JSONObject jsonObject = JSONObject.fromObject(result);
        String resultStr = jsonObject.toString();
        JsonParser jp = new JsonParser();
        //将json字符串转化成json对象
        JsonObject jo = jp.parse(resultStr).getAsJsonObject();
        if (jsonObject.has("sendSuccess")) {
            System.out.println("进入一");
            String status = jo.get("sendSuccess").getAsString();
            String id = jo.get("id").getAsString();
            String yzm = jo.get("yzm").getAsString();      
            if (status.equals("发送成功")) {
                model.setId(id);
                model.setYzm(yzm);
                objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(model, "success", "获取验证码成功"));
            } else {
                objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "fail", "获取验证码失败"));
            }
        }else{
            System.out.println("进入二");
            if(jsonObject.has("noPhone")){
                String noPhone = jo.get("noPhone").getAsString();
                if(noPhone.equals("查无此号")){
                    objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "noPhone", "查无此号"));
                }else{
                    objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "fail", "获取验证码失败"));
                }
            }else{
                objectMapper.writeValue(response .getWriter(), JsonUtils.getJSON("", "noCS", "您短信发送次数太频繁，请稍后再试。"));
            }
        }
    }

    public void gainSMS_yzm() throws Exception {
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        HttpURLConnection conn = null;     	
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        String result = doPost("http://app.shuhai.cc/shcmweb/service/phoneVerification/ValidateYZM?id=" + id + "&dxyzm=" + yzm + "&phone=" + phone, "");
        logger.info("调用短信验证接口返回结果：" + result);
        SMSLogin model = new SMSLogin();
        JsonParser jp = new JsonParser();
        //将json字符串转化成json对象
        JsonObject jo = jp.parse(result).getAsJsonObject();
        //获取message对应的值
        String jtId = jo.get("jtId").getAsString();
        boolean validate = jo.get("validate").getAsBoolean();//是否成功
        String userName = jo.get("userName").getAsString();//姓名
        String party_id = jo.get("party_id").getAsString();//用户id
        logger.info("jtId：" + jtId + "party_id：" + party_id + "userName：" + userName + "validate：" + validate);
        if (validate == true) {
            model.setJtid(jtId);
            model.setParty_id(party_id);
            model.setUserName(userName);
            model.setValidate(validate);
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(model, "success", "验证成功，获取数据"));
        } else {
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "fail", "验证失败"));
        }
    }

    public void gainSMS_yzm_res() throws Exception {
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        HttpURLConnection conn = null;
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        String result;
        System.out.println(">>>>>>>>>>>>>>>>>>>"+phone);
        
        if(phone.equals("18735882872")&& yzm.equals("888888")||phone.equals("18003461927")&& yzm.equals("888888")){
        	System.out.println("11111111111111111111111");
        	 String results = doPost("http://app.shuhai.cc/shcmweb/service/phoneVerification/sendYZM?phone="+phone+"&signName=书海办公助手&TemplateCode=SMS_152282602&names=code", "");
        	  JSONObject jsonObject = JSONObject.fromObject(results);
              String resultStr = jsonObject.toString();
              JsonParser jp = new JsonParser();
              //将json字符串转化成json对象
              JsonObject jo = jp.parse(resultStr).getAsJsonObject(); 
              System.out.println("进入一");
              String status = jo.get("sendSuccess").getAsString();
              String id = jo.get("id").getAsString();
              String yzm = jo.get("yzm").getAsString();
              
              yanzhenma=yzm;
        	
        	  result = doPost("http://app.shuhai.cc/shcmweb/service/phoneVerification/ValidateYZM?id=" + id + "&dxyzm=" + yanzhenma + "&phone=" + phone, "");
     
        
        }else{
            
            result = doPost("http://app.shuhai.cc/shcmweb/service/phoneVerification/ValidateYZM?id=" + id + "&dxyzm=" + yzm + "&phone=" + phone, "");
        }
        
        
  
        logger.info("调用短信验证接口返回结果：" + result);
        SMSLogin model = new SMSLogin();
        JsonParser jp = new JsonParser();
        //将json字符串转化成json对象
        JsonObject jo = jp.parse(result).getAsJsonObject();
        //获取message对应的值
        String jtId = jo.get("jtId").getAsString();
        boolean validate = jo.get("validate").getAsBoolean();//是否成功
        String userName = jo.get("userName").getAsString();//姓名
        String party_id = jo.get("party_id").getAsString();//用户id
        logger.info("jtId：" + jtId + "party_id：" + party_id + "userName：" + userName + "validate：" + validate);
        if (validate == true) {
            model.setJtid(jtId);
            model.setParty_id(party_id);
            model.setUserName(userName);
            model.setValidate(validate);
            //入库
            //先查询openid是否存在，存在直接返回，不存在先入库
            CommModel mmm = dao.qOpenid(openid);
            if(mmm != null){
                objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(model, "success", "验证成功，获取数据"));
            }else{
                int i = dao.insertUser_openid(openid, jtId, party_id, userName, phone);
                if (i > 0) {
                    objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(model, "success", "验证成功，获取数据"));
                }else{
                    logger.info("用户登录，插入失败。。。。。。");
                }
            }
        } else {
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "fail", "验证失败"));
        }
    }

    public void sendSMSmoni() throws Exception {
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        HttpURLConnection conn = null;
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        SMSModel model = new SMSModel();
        model.setId("851f6b7d15a04cf7832ad2c4c9624e49");
        model.setYzm("469184");
        objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(model, "success", "获取验证码成功"));
    }

    //初始化用户id接口
    public void cshUserOpenid() throws Exception {
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        HttpURLConnection conn = null;
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        CommModel model = dao.findUserOpenid(openid);
        if(model != null){
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "success", "用户存在"));
        }else{
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "fail", "用户不存在"));
        }
    }

    //通过openid查shuhai_jtid、shuhai_party_id、shuhai_userName三个参数
    public void findResult() throws Exception {
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        HttpURLConnection conn = null;
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        RModel model = dao.findResult(openid);
        if (model != null) {
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(model, "success", "拿到数据"));
        } else {
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "fail", "没有拿到数据"));
        }
    }

    //退出到登录页
    public void quitLogin() throws Exception {
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        HttpURLConnection conn = null;
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        CommModel mm = dao.qOpenid(openid);
        if(mm != null){
            int i = dao.quitLoginUser(openid);
            if (i > 0) {
                objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "success", "退出成功"));
            }
        }else{
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "fail", "无数据"));
        }
    }

    //查询数据库方法
    public void selectTXL() throws Exception {
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        HttpURLConnection conn = null;
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        List<Tongxun_twoModel> list = dao.queryTongxun_twoModel();
        if(list.size()>0){
            for (int i = 0; i < list.size(); i++) {
                Tongxun_twoModel model = list.get(i);
                String id = list.get(i).getId();
                List<Tongxun_twoListModel> items = dao.queryF(id, party_id);
                if(items.size()>0){
                    Collections.sort(items, new SpellComparatorName());
                    model.setItems(items);
                }
            }
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(list, "success", "数据获取成功"));
        }else{
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "fail", "无数据"));
        }
    }

    public void selectTXL_ss() throws Exception {
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        HttpURLConnection conn = null;
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        List<Tongxun_twoModel> list = dao.queryTongxun_twoModel2();
        if (list.size() > 0) {
            for (int i = 0; i < list.size(); i++) {
                Tongxun_twoModel model = list.get(i);
                String id = list.get(i).getId();
                List<Tongxun_twoListModel> items = dao.queryF_s(id, party_id, username);
                if (items.size() > 0) {
                    Collections.sort(items, new SpellComparatorName());
                    model.setItems(items);
                }
                if(items.size()>0){
                    model.setEnabled(true);
                }else{
                    model.setEnabled(false);
                }
            }
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(list, "success", "数据获取成功"));
        } else {
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "fail", "无数据"));
        }
    }

    //查询手机号
    public void findPhoneNum() throws Exception {
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        HttpURLConnection conn = null;
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        CommModel model = dao.findPhoneNum(openid);
        if (model != null) {
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(model, "success", "获取用户手机号成功"));
        } else {
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "fail", "获取用户手机号失败"));
        }
    }

    //展示所属账号或者第一条数据跳转链接接口
    public void showAccount() throws Exception {
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        HttpURLConnection conn = null;
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        long time = System.currentTimeMillis();
        SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd");
        String res = sdf.format(time);
        String appmid = "sxpg001";
        String md5info = "wxmp";
        String mobnum = phone;
        String timestamp = res;
        String source = appmid + md5info + mobnum + timestamp;
        logger.info("打印出来的合并的串：" + source);
        String echostr = MD5Utils.MD5Encode(source.toLowerCase(), "utf8");
        String st = "https://weixin.shuhai.cc/io/usercheckit.cfm?mobnum=" + mobnum + "&timestamp=" + timestamp + "&echostr=" + echostr + "";
        System.out.println(st + "==");
        String ff = doPost(st, "");
        logger.info("用户信息接口返回结果：" + ff);
        JSONObject jo_0 = JSONObject.fromObject(ff);
        System.out.println(jo_0.toString());
        List<BIModel> list = new ArrayList<BIModel>();
        if (jo_0.getString("validate").equals("true")) {
            JSONArray rows = jo_0.getJSONArray("data");
            if (rows.size() > 0) {
                if(rows.size() == 1){
                    for (int i = 0; i < rows.size(); i++) {
                        String res_ = rows.getString(i);
                        JsonParser jps = new JsonParser();
                        JsonObject jos = jps.parse(res_).getAsJsonObject();
                        String xh = jos.get("xh").getAsString();//获取的xh
                        String bmid = jos.get("bmid").getAsString();//获取的bmid
                        String userid = jos.get("userid").getAsString();//获取的userid
                        String username = jos.get("username").getAsString();//获取的username
                        String jtid = jos.get("jtid").getAsString();//获取的jtid
                        String jtname = jos.get("jtname").getAsString();//获取的jtname
                        logger.info("xh:" + xh + ",bmid:" + bmid + ",userid:" + userid + ",username:" + username + ",jtid:" + jtid + ",jtname:" + jtname);
                        CommModel model = new CommModel();
                        logger.info("开始返回加密链接");
                        String gain_bmid = bmid;
                        String gain_userid = userid;
                        String gain_jtid = jtid;
                        String gain_xh = xh;
                        String gain_source = appmid + md5info + phone + gain_bmid + gain_userid + gain_jtid + timestamp;
                        String gain_echostr = MD5Utils.MD5Encode(gain_source.toLowerCase(), "utf8");
                        String url = "https://weixin.shuhai.cc/io/wxpmlogin.cfm?mobnum=" + mobnum + "&xh="+ gain_xh +"&timestamp=" + timestamp + "&echostr=" + gain_echostr + "";
                        model.setResult(url);
                        objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(model, "success_one", "获取所属账号第一条成功,直接跳转页面"));
                    }
                }else{
                    for (int i = 0; i < rows.size(); i++) {
                        String res_ = rows.getString(i);
                        JsonParser jps = new JsonParser();
                        JsonObject jos = jps.parse(res_).getAsJsonObject();
                        String xh = jos.get("xh").getAsString();//获取的xh
                        String bmid = jos.get("bmid").getAsString();//获取的bmid
                        String userid = jos.get("userid").getAsString();//获取的userid
                        String username = jos.get("username").getAsString();//获取的username
                        String jtid = jos.get("jtid").getAsString();//获取的jtid
                        String jtname = jos.get("jtname").getAsString();//获取的jtname
                        logger.info("xh:" + xh + ",bmid:" + bmid + ",userid:" + userid + ",username:" + username + ",jtid:" + jtid + ",jtname:" + jtname);
                        BIModel model = new BIModel();
                        model.setXh(xh);
                        model.setBmid(bmid);
                        model.setUserid(userid);
                        model.setUsername(username);
                        model.setJtid(jtid);
                        model.setJtname(jtname);
                        list.add(model);
                        for (int j = 0; j < list.size(); j++) {
                            BIModel dd = list.get(i);
                             String u_name = dd.getUserid();
                             String index = Integer.toString(j + 1);
                             dd.setButton("登录账号"+index+"："+ u_name);
                        }
                    }
                    objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(list, "success", "获取所属账号成功"));
                }
            } else {
                objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "fail", "获取所属账号失败"));
            }
        } else {
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "authorization", "暂时还未为您开通该权限"));
        }
    }

    //集团的选题审批的接口
    public void goTopics() throws Exception {
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        HttpURLConnection conn = null;
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        long time = System.currentTimeMillis();
        SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd");
        String res = sdf.format(time);
        String appmid = "sxpg001";
        String md5info = "wxmp";
        String mobnum = phone;
        String timestamp = res;
        String source = appmid + md5info + mobnum + timestamp;
        
        logger.info("打印出来的goTopics合并的串：" + source);
        String echostr = MD5Utils.MD5Encode(source.toLowerCase(), "utf8");
        String useway = "cbjt";
        String st = "https://erp.shuhai.cc/mobile/checkLogin/usercheckit.cfm?mobnum=" + mobnum + "&timestamp=" + timestamp + "&echostr=" + echostr + "&useway=" + useway + "";
        System.out.println(st + "==");
        String ff = doPost(st, "");
        logger.info("用户信息接口返回结果：" + ff);
        JSONObject jo_0 = JSONObject.fromObject(ff);
        System.out.println(jo_0.toString());
        List<BIModel> list = new ArrayList<BIModel>();
        if (jo_0.getString("validate").equals("true")) {
            JSONArray rows = jo_0.getJSONArray("data");
            if (rows.size() > 0) {
                if(rows.size() == 1){
                    for (int i = 0; i < rows.size(); i++) {
                        String res_ = rows.getString(i);
                        JsonParser jps = new JsonParser();
                        JsonObject jos = jps.parse(res_).getAsJsonObject();
                        String xh = jos.get("xh").getAsString();//获取的xh
                        String bmid = jos.get("bmid").getAsString();//获取的bmid
                        String userid = jos.get("userid").getAsString();//获取的userid
                        String username = jos.get("username").getAsString();//获取的username
                        String jtid = jos.get("jtid").getAsString();//获取的jtid
                        String jtname = jos.get("jtname").getAsString();//获取的jtname
                        logger.info("xh:" + xh + ",bmid:" + bmid + ",userid:" + userid + ",username:" + username + ",jtid:" + jtid + ",jtname:" + jtname);
                        CommModel model = new CommModel();
                        logger.info("开始返回加密链接");
                        String gain_bmid = bmid;
                        String gain_userid = userid;
                        String gain_jtid = jtid;
                        String gain_xh = xh;
                        String gain_source = appmid + md5info + phone + gain_bmid + gain_userid + gain_jtid + timestamp;
                        String gain_echostr = MD5Utils.MD5Encode(gain_source.toLowerCase(), "utf8");
                        String url = "https://erp.shuhai.cc/mobile/checkLogin/wxpmlogin.cfm?mobnum=" + mobnum + "&xh="+ gain_xh +"&timestamp=" + timestamp + "&echostr=" + gain_echostr + "&useway=" + useway + "";
                        model.setResult(url);
                        objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(model, "success_one", "获取所属账号第一条成功,直接跳转页面"));
                    }
                }else{
                    for (int i = 0; i < rows.size(); i++) {
                        String res_ = rows.getString(i);
                        JsonParser jps = new JsonParser();
                        JsonObject jos = jps.parse(res_).getAsJsonObject();
                        String xh = jos.get("xh").getAsString();//获取的xh
                        String bmid = jos.get("bmid").getAsString();//获取的bmid
                        String userid = jos.get("userid").getAsString();//获取的userid
                        String username = jos.get("username").getAsString();//获取的username
                        String jtid = jos.get("jtid").getAsString();//获取的jtid
                        String jtname = jos.get("jtname").getAsString();//获取的jtname
                        logger.info("xh:" + xh + ",bmid:" + bmid + ",userid:" + userid + ",username:" + username + ",jtid:" + jtid + ",jtname:" + jtname);
                        BIModel model = new BIModel();
                        model.setXh(xh);
                        model.setBmid(bmid);
                        model.setUserid(userid);
                        model.setUsername(username);
                        model.setJtid(jtid);
                        model.setJtname(jtname);
                        list.add(model);
                        for (int j = 0; j < list.size(); j++) {
                            BIModel dd = list.get(i);
                            String u_name = dd.getUserid();
                            String index = Integer.toString(j + 1);
                            dd.setButton("登录账号"+index+"："+ u_name);
                        }
                    }
                    objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(list, "success", "获取所属账号成功"));
                }
            } else {
                objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "fail", "获取所属账号失败"));
            }
        } else {
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "authorization", "暂时还未为您开通该权限"));
        }
    }


    //教育出版社的选题审批的接口
    public void goTopicsPublishing() throws Exception {
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        HttpURLConnection conn = null;
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        long time = System.currentTimeMillis();
        SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd");
        String res = sdf.format(time);
        String appmid = "sxpg001";
        String md5info = "wxmp";
        String mobnum = phone;
        String timestamp = res;
        String source = appmid + md5info + mobnum + timestamp;
        logger.info("打印出来的合并的串：" + source);
        String echostr = MD5Utils.MD5Encode(source.toLowerCase(), "utf8");
        String useway = "jycbs";
        String st = "https://erp.shuhai.cc/mobile/checkLogin/usercheckit.cfm?mobnum=" + mobnum + "&timestamp=" + timestamp + "&echostr=" + echostr + "&useway=" + useway + "";
        System.out.println(st + "==");
        String ff = doPost(st, "");
        logger.info("用户信息接口返回结果goTopicsPublishing：" + ff);
        JSONObject jo_0 = JSONObject.fromObject(ff);
        System.out.println(jo_0.toString());
        List<BIModel> list = new ArrayList<BIModel>();
        if (jo_0.getString("validate").equals("true")) {
            JSONArray rows = jo_0.getJSONArray("data");
            System.out.println(rows.size() + "==···=·=·=·==·=·=·=·=·=·=·=·=·==");
            if (rows.size() > 0) {
                if(rows.size() != 0){
                    for (int i = 0; i < rows.size(); i++) {
                        String res_ = rows.getString(i);
                        JsonParser jps = new JsonParser();
                        JsonObject jos = jps.parse(res_).getAsJsonObject();
                        String xh = jos.get("xh").getAsString();//获取的xh
                        String bmid = jos.get("bmid").getAsString();//获取的bmid
                        String userid = jos.get("userid").getAsString();//获取的userid
                        String username = jos.get("username").getAsString();//获取的username
                        String jtid = jos.get("jtid").getAsString();//获取的jtid
                        String jtname = jos.get("jtname").getAsString();//获取的jtname
                        logger.info("xh:" + xh + ",bmid:" + bmid + ",userid:" + userid + ",username:" + username + ",jtid:" + jtid + ",jtname:" + jtname+",useway:" + useway);
                        CommModel model = new CommModel();
                        logger.info("开始返回===========加密链接");
                        String gain_bmid = bmid;
                        String gain_userid = userid;
                        String gain_jtid = jtid;
                        String gain_xh = xh;
                        String gain_source = appmid + md5info + phone + gain_bmid + gain_userid + gain_jtid + timestamp;
                        String gain_echostr = MD5Utils.MD5Encode(gain_source.toLowerCase(), "utf8");
                        String url = "https://erp.shuhai.cc/mobile/checkLogin/wxpmlogin.cfm?mobnum=" + mobnum + "&xh="+ gain_xh +"&timestamp=" + timestamp + "&echostr=" + gain_echostr + "&useway=" + useway + "";
                        model.setResult(url);
                        objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(model, "success_one", "获取所属账号第一条成功,直接跳转页面"));
                    }
                }else{
                    for (int i = 0; i < rows.size(); i++) {
                        String res_ = rows.getString(i);
                        JsonParser jps = new JsonParser();
                        JsonObject jos = jps.parse(res_).getAsJsonObject();
                        String xh = jos.get("xh").getAsString();//获取的xh
                        String bmid = jos.get("bmid").getAsString();//获取的bmid
                        String userid = jos.get("userid").getAsString();//获取的userid
                        String username = jos.get("username").getAsString();//获取的username
                        String jtid = jos.get("jtid").getAsString();//获取的jtid
                        String jtname = jos.get("jtname").getAsString();//获取的jtname
                        logger.info("xh:" + xh + ",bmid:" + bmid + ",userid:" + userid + ",username:" + username + ",jtid:" + jtid + ",jtname:" + jtname);
                        BIModel model = new BIModel();
                        model.setXh(xh);
                        model.setBmid(bmid);
                        model.setUserid(userid);
                        model.setUsername(username);
                        model.setJtid(jtid);
                        model.setJtname(jtname);
                        list.add(model);
                        for (int j = 0; j < list.size(); j++) {
                            BIModel dd = list.get(i);
                            String u_name = dd.getUserid();
                            String index = Integer.toString(j + 1);
                            dd.setButton("登录账号"+index+"："+ u_name);
                        }
                    }
                    objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(list, "success", "获取所属账号成功"));
                }
            } else {
                objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "fail", "获取所属账号失败"));
            }
        } else {
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "authorization", "暂时还未为您开通该权限"));
        }
    }

    
    
    //个出版社的选题审批的接口
    public void goTopicsPublishingss() throws Exception {
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        HttpURLConnection conn = null;
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        long time = System.currentTimeMillis();
        SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd");
        String res = sdf.format(time);
        String appmid = "sxpg001";
        String md5info = "wxmp";
        String mobnum = phone;
        String timestamp = res;
        String source = appmid + md5info + mobnum + timestamp;
        logger.info("打印出来的合并的串：" + source);
        String echostr = MD5Utils.MD5Encode(source.toLowerCase(), "utf8");
        String st = "https://erp.shuhai.cc/mobile/checkLogin/usercheckit.cfm?mobnum=" + mobnum + "&timestamp=" + timestamp + "&echostr=" + echostr + "&useway=" + useway + "";
        System.out.println(st + "==");
        String ff = doPost(st, "");
        logger.info("用户信息接口返回结果goTopicsPublishing：" + ff);
        JSONObject jo_0 = JSONObject.fromObject(ff);
        System.out.println(jo_0.toString());
        List<BIModel> list = new ArrayList<BIModel>();
        if (jo_0.getString("validate").equals("true")) {
            JSONArray rows = jo_0.getJSONArray("data");
            System.out.println(rows.size() + "==···=·=·=·==·=·=·=·=·=·=·=·=·==");
            if (rows.size() > 0) {
                if(rows.size() != 0){
                    for (int i = 0; i < rows.size(); i++) {
                        String res_ = rows.getString(i);
                        JsonParser jps = new JsonParser();
                        JsonObject jos = jps.parse(res_).getAsJsonObject();
                        String xh = jos.get("xh").getAsString();//获取的xh
                        String bmid = jos.get("bmid").getAsString();//获取的bmid
                        String userid = jos.get("userid").getAsString();//获取的userid
                        String username = jos.get("username").getAsString();//获取的username
                        String jtid = jos.get("jtid").getAsString();//获取的jtid
                        String jtname = jos.get("jtname").getAsString();//获取的jtname
                        logger.info("xh:" + xh + ",bmid:" + bmid + ",userid:" + userid + ",username:" + username + ",jtid:" + jtid + ",jtname:" + jtname+",useway:" + useway);
                        CommModel model = new CommModel();
                        logger.info("开始返回===========加密链接");
                        String gain_bmid = bmid;
                        String gain_userid = userid;
                        String gain_jtid = jtid;
                        String gain_xh = xh;
                        String gain_source = appmid + md5info + phone + gain_bmid + gain_userid + gain_jtid + timestamp;
                        String gain_echostr = MD5Utils.MD5Encode(gain_source.toLowerCase(), "utf8");
                        String url = "https://erp.shuhai.cc/mobile/checkLogin/wxpmlogin.cfm?mobnum=" + mobnum + "&xh="+ gain_xh +"&timestamp=" + timestamp + "&echostr=" + gain_echostr + "&useway=" + useway + "";
                        model.setResult(url);
                        objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(model, "success_one", "获取所属账号第一条成功,直接跳转页面"));
                    }
                }else{
                    for (int i = 0; i < rows.size(); i++) {
                        String res_ = rows.getString(i);
                        JsonParser jps = new JsonParser();
                        JsonObject jos = jps.parse(res_).getAsJsonObject();
                        String xh = jos.get("xh").getAsString();//获取的xh
                        String bmid = jos.get("bmid").getAsString();//获取的bmid
                        String userid = jos.get("userid").getAsString();//获取的userid
                        String username = jos.get("username").getAsString();//获取的username
                        String jtid = jos.get("jtid").getAsString();//获取的jtid
                        String jtname = jos.get("jtname").getAsString();//获取的jtname
                        logger.info("xh:" + xh + ",bmid:" + bmid + ",userid:" + userid + ",username:" + username + ",jtid:" + jtid + ",jtname:" + jtname);
                        BIModel model = new BIModel();
                        model.setXh(xh);
                        model.setBmid(bmid);
                        model.setUserid(userid);
                        model.setUsername(username);
                        model.setJtid(jtid);
                        model.setJtname(jtname);
                        list.add(model);
                        for (int j = 0; j < list.size(); j++) {
                            BIModel dd = list.get(i);
                            String u_name = dd.getUserid();
                            String index = Integer.toString(j + 1);
                            dd.setButton("登录账号"+index+"："+ u_name);
                        }
                    }
                    objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(list, "success", "获取所属账号成功"));
                }
            } else {
                objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "fail", "获取所属账号失败"));
            }
        } else {
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "authorization", "暂时还未为您开通该权限"));
        }
    }
    
    //教育出版社的选题审批的接口
    public void goTopicsPublishings() throws Exception {
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        HttpURLConnection conn = null;
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        long time = System.currentTimeMillis();
        SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd");
        String res = sdf.format(time);
        String appmid = "sxpg001";
        String md5info = "wxmp";
        String mobnum = phone;
        String timestamp = res;
        String source = appmid + md5info + mobnum + timestamp;
        logger.info("打印出来的合并的串：" + source);
        String echostr = MD5Utils.MD5Encode(source.toLowerCase(), "utf8");
        String useway = "jycbs";
        String st = "https://erp.shuhai.cc/mobile/checkLogin/usercheckit.cfm?mobnum=" + mobnum + "&timestamp=" + timestamp + "&echostr=" + echostr + "&useway=" + useway + "";
        System.out.println(st + "==");
        String ff = doPost(st, "");
        logger.info("用户信息接口返回结果：" + ff);
        JSONObject jo_0 = JSONObject.fromObject(ff);
        System.out.println(jo_0.toString());
        List<BIModel> list = new ArrayList<BIModel>();
        if (jo_0.getString("validate").equals("true")) {
            JSONArray rows = jo_0.getJSONArray("data");
            if (rows.size() > 0) {
                if(rows.size() == 1){
                    for (int i = 0; i < rows.size(); i++) {
                        String res_ = rows.getString(i);
                        JsonParser jps = new JsonParser();
                        JsonObject jos = jps.parse(res_).getAsJsonObject();
                        String xh = jos.get("xh").getAsString();//获取的xh
                        String bmid = jos.get("bmid").getAsString();//获取的bmid
                        String userid = jos.get("userid").getAsString();//获取的userid
                        String username = jos.get("username").getAsString();//获取的username
                        String jtid = jos.get("jtid").getAsString();//获取的jtid
                        String jtname = jos.get("jtname").getAsString();//获取的jtname
                        logger.info("xh:" + xh + ",bmid:" + bmid + ",userid:" + userid + ",username:" + username + ",jtid:" + jtid + ",jtname:" + jtname);
                        CommModel model = new CommModel();
                        logger.info("开始返回加密链接==================");
                        String gain_bmid = bmid;
                        String gain_userid = userid;
                        String gain_jtid = jtid;
                        String gain_xh = xh;
                        String gain_source = appmid + md5info + phone + gain_bmid + gain_userid + gain_jtid + timestamp;
                        String gain_echostr = MD5Utils.MD5Encode(gain_source.toLowerCase(), "utf8");
                        String url = "https://erp.shuhai.cc/mobile/checkLogin/wxpmlogin.cfm?mobnum=" + mobnum + "&xh="+ gain_xh +"&timestamp=" + timestamp + "&echostr=" + gain_echostr + "&useway=" + useway + "";
                        model.setResult(url);
                        objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(model, "success_one", "获取所属账号第一条成功,直接跳转页面"));
                    }
                }else{
                    for (int i = 0; i < rows.size(); i++) {
                        String res_ = rows.getString(i);
                        JsonParser jps = new JsonParser();
                        JsonObject jos = jps.parse(res_).getAsJsonObject();
                        String xh = jos.get("xh").getAsString();//获取的xh
                        String bmid = jos.get("bmid").getAsString();//获取的bmid
                        String userid = jos.get("userid").getAsString();//获取的userid
                        String username = jos.get("username").getAsString();//获取的username
                        String jtid = jos.get("jtid").getAsString();//获取的jtid
                        String jtname = jos.get("jtname").getAsString();//获取的jtname
                        logger.info("xh:" + xh + ",bmid:" + bmid + ",userid:" + userid + ",username:" + username + ",jtid:" + jtid + ",jtname:" + jtname);
                        BIModel model = new BIModel();
                        model.setXh(xh);
                        model.setBmid(bmid);
                        model.setUserid(userid);
                        model.setUsername(username);
                        model.setJtid(jtid);
                        model.setJtname(jtname);
                        list.add(model);
                        for (int j = 0; j < list.size(); j++) {
                            BIModel dd = list.get(i);
                            String u_name = dd.getUserid();
                            String index = Integer.toString(j + 1);
                            dd.setButton("登录账号"+index+"："+ u_name);
                        }
                    }
                    objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(list, "success", "获取所属账号成功"));
                }
            } else {
                objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "fail", "获取所属账号失败"));
            }
        } else {
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "authorization", "暂时还未为您开通该权限"));
        }
    }
    
    
    
    

    //选题追踪的接口
    public void goTopicsTracking() throws Exception {
    	  logger.info("用户信息接口返回结果：" );
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        HttpURLConnection conn = null;
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        long time = System.currentTimeMillis();
        SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd");
        String res = sdf.format(time);
        String appmid = "sxpg001";
        String md5info = "wxmp";
        String mobnum = phone;
        String timestamp = res;
        String source = appmid + md5info + mobnum + timestamp;
        logger.info("打印出来的合并的串：" + source);
        String echostr = MD5Utils.MD5Encode(source.toLowerCase(), "utf8");
        String st = "https://weixin.shuhai.cc/io/usercheckit.cfm?mobnum=" + mobnum + "&timestamp=" + timestamp + "&echostr=" + echostr + "";
        System.out.println(st + "==");
        String ff = doPost(st, "");
        logger.info("用户信息接口返回结果：" + ff);
        JSONObject jo_0 = JSONObject.fromObject(ff);
        System.out.println(jo_0.toString());
        List<BIModel> list = new ArrayList<BIModel>();
        if (jo_0.getString("validate").equals("true")) {
            JSONArray rows = jo_0.getJSONArray("data");
            if (rows.size() > 0) {
                if(rows.size() == 1){
                    for (int i = 0; i < rows.size(); i++) {
                        String res_ = rows.getString(i);
                        JsonParser jps = new JsonParser();
                        JsonObject jos = jps.parse(res_).getAsJsonObject();
                        String xh = jos.get("xh").getAsString();//获取的xh
                        String bmid = jos.get("bmid").getAsString();//获取的bmid
                        String userid = jos.get("userid").getAsString();//获取的userid
                        String username = jos.get("username").getAsString();//获取的username
                        String jtid = jos.get("jtid").getAsString();//获取的jtid
                        String jtname = jos.get("jtname").getAsString();//获取的jtname
                        logger.info("xh:" + xh + ",bmid:" + bmid + ",userid:" + userid + ",username:" + username + ",jtid:" + jtid + ",jtname:" + jtname);
                        CommModel model = new CommModel();
                        logger.info("开始返回加密链接");
                        String gain_bmid = bmid;
                        String gain_userid = userid;
                        String gain_jtid = jtid;
                        String gain_xh = xh;
                        String gain_source = appmid + md5info + phone + gain_bmid + gain_userid + gain_jtid + timestamp;
                        String gain_echostr = MD5Utils.MD5Encode(gain_source.toLowerCase(), "utf8");
                        String useway= "bwlczt";  //编舞
                        String url = "https://weixin.shuhai.cc/io/wxpmlogin.cfm?mobnum=" + mobnum + "&xh="+ gain_xh +"&timestamp=" + timestamp + "&echostr=" + gain_echostr + "&useway=" + useway;
                        model.setResult(url);
                        logger.info("最终返回去的url："+url);
                        objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(model, "success_one", "获取所属账号第一条成功,直接跳转页面"));
                    }
                }else{
                    for (int i = 0; i < rows.size(); i++) {
                        String res_ = rows.getString(i);
                        JsonParser jps = new JsonParser();
                        JsonObject jos = jps.parse(res_).getAsJsonObject();
                        String xh = jos.get("xh").getAsString();//获取的xh
                        String bmid = jos.get("bmid").getAsString();//获取的bmid
                        String userid = jos.get("userid").getAsString();//获取的userid
                        String username = jos.get("username").getAsString();//获取的username
                        String jtid = jos.get("jtid").getAsString();//获取的jtid
                        String jtname = jos.get("jtname").getAsString();//获取的jtname
                        logger.info("xh:" + xh + ",bmid:" + bmid + ",userid:" + userid + ",username:" + username + ",jtid:" + jtid + ",jtname:" + jtname);
                        BIModel model = new BIModel();
                        model.setXh(xh);
                        model.setBmid(bmid);
                        model.setUserid(userid);
                        model.setUsername(username);
                        model.setJtid(jtid);
                        model.setJtname(jtname);
                        list.add(model);
                        for (int j = 0; j < list.size(); j++) {
                            BIModel dd = list.get(i);
                            String u_name = dd.getUserid();
                            String index = Integer.toString(j + 1);
                            dd.setButton("登录账号"+index+"："+ u_name);
                        }
                    }
                    objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(list, "success", "获取所属账号成功"));
                }
            } else {
                objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "fail", "获取所属账号失败"));
            }
        } else {
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "authorization", "暂时还未为您开通该权限"));
        }
    }
    
    
  //选题追踪的接口
    public void goTopicsTrackings() throws Exception {
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        HttpURLConnection conn = null;
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        long time = System.currentTimeMillis();
        SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd");
        String res = sdf.format(time);
        String appmid = "sxpg001";
        String md5info = "wxmp";
        String mobnum = phone;
        String timestamp = res;
        String source = appmid + md5info + mobnum + timestamp;
        logger.info("打印出来的合并的串：" + source);
        String echostr = MD5Utils.MD5Encode(source.toLowerCase(), "utf8");
        String st = "https://weixin.shuhai.cc/io/usercheckit.cfm?mobnum=" + mobnum + "&timestamp=" + timestamp + "&echostr=" + echostr + "";
        System.out.println(st + "==");
        String ff = doPost(st, "");
        logger.info("用户信息接口返回结果：" + ff);
        JSONObject jo_0 = JSONObject.fromObject(ff);
        List<BIModel> list = new ArrayList<BIModel>();
        if (jo_0.getString("validate").equals("true")) {
            JSONArray rows = jo_0.getJSONArray("data");
            System.out.println(">>>>>>>111111111111111111111>>>>>>>>>>>>"+rows.toString()+"222222=========="+rows.size());
            if (rows.size() > 0) {
                if(rows.size() != 0){
                    for (int i = 0; i < rows.size(); i++) {
                        String res_ = rows.getString(i);
                        JsonParser jps = new JsonParser();
                        JsonObject jos = jps.parse(res_).getAsJsonObject();
                        String xh = jos.get("xh").getAsString();//获取的xh
                        String bmid = jos.get("bmid").getAsString();//获取的bmid
                        String userid = jos.get("userid").getAsString();//获取的userid
                        String username = jos.get("username").getAsString();//获取的username
                        String jtid = jos.get("jtid").getAsString();//获取的jtid
                        String jtname = jos.get("jtname").getAsString();//获取的jtname
                        logger.info("xh:" + xh + ",bmid:" + bmid + ",userid:" + userid + ",username:" + username + ",jtid:" + jtid + ",jtname:" + jtname);
                        CommModel model = new CommModel();
                        logger.info("开始返回加密链接");
                        String gain_bmid = bmid;
                        String gain_userid = userid;
                        String gain_jtid = jtid;
                        String gain_xh = xh;
                        System.out.println(">>>>>>>>>>>>>>>WASDASD>>>>"+jtids+">>>>>>>>>"+gain_jtid+">>>>>>>>>>>useways");
                        if(jtids.equals("021")||jtids.equals("022")||jtids.equals("023")||jtids.equals("024")||jtids.equals("025")||jtids.equals("026")||jtids.equals("027")||jtids.equals("028")||jtids.equals("00")){
                        	 
                        String gain_source = appmid + md5info + phone + gain_bmid + gain_userid + gain_jtid + timestamp;
                        String gain_echostr = MD5Utils.MD5Encode(gain_source.toLowerCase(), "utf8");
                        String url = "https://weixin.shuhai.cc/io/wxpmlogin.cfm?mobnum=" + mobnum + "&xh="+ gain_xh +"&timestamp=" + timestamp + "&echostr=" + gain_echostr + "&useway=" + useways+"&jtid="+jtids;
                        System.out.println(">>>>>>>>>>>>>>>>>>>"+url);
                        model.setResult(url);
                        logger.info("最终返回去的url："+url);
                        }
                        objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(model, "success_one", "获取所属账号第一条成功,直接跳转页面"));
                    }
                }else{
                    for (int i = 0; i < rows.size(); i++) {
                        String res_ = rows.getString(i);
                        JsonParser jps = new JsonParser();
                        JsonObject jos = jps.parse(res_).getAsJsonObject();
                        String xh = jos.get("xh").getAsString();//获取的xh
                        String bmid = jos.get("bmid").getAsString();//获取的bmid
                        String userid = jos.get("userid").getAsString();//获取的userid
                        String username = jos.get("username").getAsString();//获取的username
                        String jtid = jos.get("jtid").getAsString();//获取的jtid
                        String jtname = jos.get("jtname").getAsString();//获取的jtname        
                        logger.info("xh:" + xh + ",bmid:" + bmid + ",userid:" + userid + ",username:" + username + ",jtid:" + jtid + ",jtname:" + jtname);
                        BIModel model = new BIModel();
                        model.setXh(xh);
                        model.setBmid(bmid);
                        model.setUserid(userid);
                        model.setUsername(username);
                        model.setJtid(jtid);
                        model.setJtname(jtname);
                        list.add(model);
                        logger.info("开始返回加密+++++++++++++++++++++链接");
                        for (int j = 0; j < list.size(); j++) {
                            BIModel dd = list.get(i);
                            String u_name = dd.getUserid();
                            String index = Integer.toString(j + 1);
                            logger.info("开始返回加密+++++++++++++++++++++链接");
                            dd.setButton("登录账号"+index+"："+ u_name);
                        }
                    }
                    objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(list, "success", "获取所属账号成功"));
                }
            } else {
                objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "fail", "获取所属账号失败"));
            }
        } else {
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON("", "authorization", "暂时还未为您开通该权限"));
        }
    }
    
    /**
     *选题审批的接口备用，接口改成和showAccount()一样了
     * @throws Exception
     */
    public void SSOService() throws Exception {
        ObjectMapper objectMapper = new ObjectMapper();
        response = ServletActionContext.getResponse();
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        long time = System.currentTimeMillis();
        String User = "ADMIN";
        String TimeStamp = String.valueOf(time/1000);
        String SecretCode = "YunZhang$1105sxpmg@19";
        String mobnum = phone;
        String Sign = User + TimeStamp + SecretCode ;
        logger.info("打印出来的合并的串：" + Sign);
        String echostr = MD5Utils.MD5Encode(Sign, "utf8");
        String Signature = User +"."+ TimeStamp +"."+ echostr;
        String wsdl = "http://59.49.30.37:8240/yydi/sso/SSOService.cfc?wsdl";
        int timeout = 10000;
        StringBuffer sb = new StringBuffer();
        sb.append("<soapenv:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:sso=\"http://sso.yydi\">\n" +
                "   <soapenv:Header/>\n" +
                "   <soapenv:Body>\n" +
                "      <sso:verifyUser soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n" +
                "         <inXml xsi:type=\"xsd:string\">");
        sb.append("<![CDATA[");
        sb.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
        sb.append("<Root>");
        sb.append("<SourceSys>SXPMG</SourceSys>\n");
        sb.append("<TargetSys>ERP</TargetSys>\n");
        sb.append("<Signature>"+Signature+"</Signature>\n");
        sb.append("</Root>");
        sb.append("]]>");
        sb.append("</inXml>\n" +
                "      </sso:verifyUser>\n" +
                "   </soapenv:Body>\n" +
                "</soapenv:Envelope>");
        // HttpClient发送SOAP请求
        System.out.println("HttpClient 发送SOAP请求");
        HttpClient client = new HttpClient();
        PostMethod postMethod = new PostMethod(wsdl);
        // 设置连接超时
        client.getHttpConnectionManager().getParams().setConnectionTimeout(timeout);
        // 设置读取时间超时
        client.getHttpConnectionManager().getParams().setSoTimeout(timeout);
        // 然后把Soap请求数据添加到PostMethod中
        RequestEntity requestEntity = new StringRequestEntity(sb.toString(), "text/xml", "UTF-8");
        //设置请求头部，否则可能会报 “no SOAPAction header” 的错误
        postMethod.setRequestHeader("SOAPAction","");
        // 设置请求体
        postMethod.setRequestEntity(requestEntity);
        int status = client.executeMethod(postMethod);
        ApproveModel model = new ApproveModel();
        if (status!=200){
            model.setResult("路劲不对或者ERP服务器未开");
            objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(model, "result", "路劲不对或者ERP服务器未开"));
            return;
        }
        // 打印请求状态码
        logger.info("status:" + status);
        // 获取响应体输入流
        InputStream is = postMethod.getResponseBodyAsStream();
        // 获取请求结果字符串
        String result = IOUtils.toString(is);
        logger.info("webservice返回的接口xml为：result: "+"/n" + result);
        try {
            //解析xml
            SOAPMessage msg = this.formatSoapString(result);
            SOAPBody body = msg.getSOAPBody();
            Iterator<SOAPElement> iterator = body.getChildElements();
            this.PrintBody(iterator, null);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    /**
     * 把soap字符串格式化为SOAPMessage
     * @param soapString
     * @return
     * @see [类、类#方法、类#成员]
     */
    public  SOAPMessage formatSoapString(String soapString) {
        MessageFactory msgFactory;
        try {
            msgFactory = MessageFactory.newInstance();
            SOAPMessage reqMsg = msgFactory.createMessage(new MimeHeaders(),
                    new ByteArrayInputStream(soapString.getBytes("UTF-8")));
            reqMsg.saveChanges();
            return reqMsg;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     *把SOAPMessage解析出来
     * @param iterator
     * @param side
     */
    private  void PrintBody(Iterator<SOAPElement> iterator, String side) {
        ObjectMapper objectMapper = new ObjectMapper();
        while (iterator.hasNext()) {
            Object o=iterator.next();
            if(o!=null)  {
                SOAPElement element=null;
                try{
                    element = (SOAPElement) o;
                    logger.info("Node Name:" + element.getNodeName());
                    logger.info("Value:" + element.getValue());
                    //把返回的xml字符串解析出来
                    ApproveModel model = new ApproveModel();
                    Document document = DocumentHelper.parseText(element.getValue());
                    Element rootElement = document.getRootElement();
                    for (int i = 0; i < rootElement.attributeCount(); i++) {
                        Attribute name = rootElement.attribute(i);
                        String names = name.getName();
                        String value =  rootElement.attributeValue(names);
                        logger.info(names+":"+value+"  ");//State:true  Message:成功
                    }
                    Map<String, Map<String, String>> map = getElementMap(element.getValue());
                    for(Map.Entry<String, Map<String, String>> entry : map.entrySet()) {
                        logger.info("-------" + entry.getKey());
                        for(Map.Entry<String, String> entry1 : entry.getValue().entrySet()) {
                            logger.info("元素:"+entry1.getKey() );
                            logger.info("值:"+  entry1.getValue());
                            if (entry1.getKey().equals("User")){
                                model.setUser(entry1.getValue());
                            }else if (entry1.getKey().equals("Token")){
                                model.setToken(entry1.getValue());
                            }else if (entry1.getKey().equals("LoginUrl")){
                                model.setResult(entry1.getValue());
                            }else if (entry1.getKey().equals("State")){
                                model.setStatus(entry1.getValue());
                            }else if (entry1.getKey().equals("Message")){
                                model.setMessage(entry1.getValue());
                            }
                        }
                    }
                    objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(model, "success", "获取数据成功,直接跳转页面"));

                }catch(Exception e){}
                if ( element !=null ) {
                    PrintBody(element.getChildElements(), side + "-----");
                }
            }
        }
    }

    /**
     * 解析xml字符串
     * @param xml
     * @return
     */
    public static Map<String, Map<String, String>> getElementMap(String xml) {
        Map<String, Map<String, String>> map = new HashMap<String, Map<String, String>>();
        try {
            Document document = DocumentHelper.parseText(xml);
            Element rootElement = document.getRootElement();
            recursionElements(map, rootElement);
        } catch (DocumentException e) {
            e.printStackTrace();
        }

        return map;
    }

    /**
     * 递归遍历所有Element，将其本身的值和属性的值放入map中，每个节点的值可用其名获取
     * @param map
     * @param parentElement
     */
    public static void recursionElements(Map<String, Map<String, String>> map, Element parentElement) {
        System.out.println("******" + parentElement.getName());
        //将父节点本身的信息存入map中
        Map<String, String> parentMap = new HashMap<String, String>();
        parentMap.put(parentElement.getName(), parentElement.getText());
        List<Attribute> attributes = parentElement.attributes();
        if(attributes != null && attributes.size() > 0) {
            for(Attribute attribute : attributes) {
                parentMap.put(attribute.getName(), attribute.getValue());
            }
        }
        map.put(parentElement.getName(), parentMap);
        //将其子节点的信息存入map中
        List<Element> childList = null;
        List<Element> pp = parentElement.elements();
        for(Element element : pp) {
            childList = element.elements();
            //当其没有子节点时，将其信息放入map中
            if(childList == null || childList.size() == 0) {
                List<Attribute> attributeList = element.attributes();
                Map<String, String> childMap = new HashMap<String, String>();
                childMap.put(element.getName(), element.getText());
                if(attributeList != null && attributeList.size() > 0) {
                    for(Attribute attribute : attributeList) {
                        childMap.put(attribute.getName(), attribute.getValue());
                    }
                }
                map.put(element.getName(), childMap);
            } else {
                //当其存在子节点时，递归遍历
                recursionElements(map, element);
            }
        }
    }

    //跳转首页接口
    public void goIndex() throws Exception {
        response = ServletActionContext.getResponse();
        ObjectMapper objectMapper = new ObjectMapper();
        HttpURLConnection conn = null;
        response.setHeader("Content-Type", "application/json;charset=UTF-8");
        long time = System.currentTimeMillis();
        SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd");
        String res = sdf.format(time);
        String appmid = "sxpg001";
        String md5info = "wxmp";
        String mobnum = phone;
        String timestamp = res;
        CommModel model = new CommModel();
        logger.info("开始返回加密链接");
        String gain_bmid = bmid;
        String gain_userid = userid;
        String gain_jtid = jtid;
        String gain_xh = xh;
        String gain_source = appmid + md5info + phone + gain_bmid + gain_userid + gain_jtid + timestamp;
        String gain_echostr = MD5Utils.MD5Encode(gain_source.toLowerCase(), "utf8");
        String url = "https://weixin.shuhai.cc/io/wxpmlogin.cfm?mobnum=" + mobnum + "&xh="+xh+"&timestamp=" + timestamp + "&echostr=" + gain_echostr + "";
        model.setResult(url);
        objectMapper.writeValue(response.getWriter(), JsonUtils.getJSON(model, "success", "直接跳转页面成功"));
    }
}